Borrar filtros
Borrar filtros

How do I create a for loop for the this example?

1 visualización (últimos 30 días)
Francis Trombini
Francis Trombini el 15 de Oct. de 2022
Comentada: Francis Trombini el 18 de Oct. de 2022
accelX_cd1 = accelX(i_start_cd1:i_end_cd1);
accelY_cd1 = accelY(i_start_cd1:i_end_cd1);
accelZ_cd1 = accelZ(i_start_cd1:i_end_cd1);
accelX_cd2 = accelX (i_start_cd2:i_end_cd2);
accelY_cd2 = accelY (i_start_cd2:i_end_cd2);
accelZ_cd2 = accelZ (i_start_cd2:i_end_cd2);
accelX_cd3 = accelX (i_start_cd3:i_end_cd3);
accelY_cd3 = accelY (i_start_cd3:i_end_cd3);
accelZ_cd3 = accelZ (i_start_cd3:i_end_cd3);
accelX_cd4 = accelX (i_start_cd4:i_end_cd4);
accelY_cd4 = accelY (i_start_cd4:i_end_cd4);
accelZ_cd4 = accelZ (i_start_cd4:i_end_cd4);
accelX_cd5 = accelX (i_start_cd5:i_end_cd5);
accelY_cd5 = accelY (i_start_cd5:i_end_cd5);
accelZ_cd5 = accelZ (i_start_cd5:i_end_cd5);
accelX_cd6 = accelX (i_start_cd6:i_end_cd6);
accelY_cd6 = accelY (i_start_cd6:i_end_cd6);
accelZ_cd6 = accelZ (i_start_cd6:i_end_cd6);
  1 comentario
Ghazwan
Ghazwan el 15 de Oct. de 2022
You need to arrange them in arrays, with the columns (or rows) being the variables you need to loop.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 15 de Oct. de 2022
The solution is easy, if you do not hide the index in the name of the variable as in i_end_cd1, i_end_cd2, ... Use a vector instead and real indices: i_end_cd(1), i_end_cd(2), ...
  5 comentarios
Jan
Jan el 17 de Oct. de 2022
"I named these segments condition 1 (cd1), condition 2 (cd2), condition 3 (cd3), condition 4 (cd4), condition 5 (cd5) and condition 6 (cd6)" - this is the problem already. Use arrays instead: Cond(1), Cond(2), ... I avoid to use "cd" as name of a variable, because this collides with the cd() command.
If you work with arrays, running a loop is trivial:
for k = 1:6
disp(Cond(k)) % Or whatever
end
Francis Trombini
Francis Trombini el 18 de Oct. de 2022
Thank you for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by