How to do a same function on variables with similiar parts in their names?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
let's say we have variables named as: Time_p1 and Voltage_p1
Time_p2 and Voltage_p2
Time_p3 and Voltage_p3
and so on.
we want to do the following set of comments on each of them.
for Time_p1 and Voltage_p1:
pulse1=[];
pulse1(:,1)= Time_p1;
pulse1(:,2)= Voltage_p1
for Time_p2 and Voltage_p2:
pulse2=[];
pulse2(:,1)= Time_p2;
pulse2(:,2)= Voltage_p2;
and so on.
how can we do this in a simple way?
0 comentarios
Respuestas (1)
Steven Lord
el 10 de Dic. de 2020
let's say we have variables named as: Time_p1 and Voltage_p1
Time_p2 and Voltage_p2
Time_p3 and Voltage_p3
and so on.
we want to do the following set of comments on each of them.
how can we do this in a simple way?
Instead of having multiple variables names that only differ by a number, store them in a numeric array (if they can be combined into a rectangular region) or a cell array (if they can't.)
x = (1:5).';
y = x.^(0:6)
Instead of defining y0 = x.^0, y1 = x.^1, y2 = x.^2, etc. use y(0+1) for x.^0, y(1+1) for x.^1, y(2+1) for x.^2, etc.
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!