How do I create a for loop for the this example?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ghazwan
2022-10-15
You need to arrange them in arrays, with the columns (or rows) being the variables you need to loop.
采纳的回答
Jan
2022-10-15
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 个评论
Jan
2022-10-17
"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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!