"Continue" in "for loop" based on trial count

2 次查看(过去 30 天)
I have the following loop set up:
X_vector = [3; -3; -9; -15; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -15; -9; -3; 3;];
Y_vector = [15; 15; 15; 15; 9; 9; 9; 9; 9; 3; 3; 3; 3; 3; -3; -3; -3; -3; -3; -9; -9; -9; -9; -9; -15; -15; -15; -15;];
for k = 1 : numel(X_vector)
x = X_vector(k);
y = Y_vector(k);
% Now use x and y in some way.
end
I want the loop to run through all the X and Y vector locations but change every 5 trials to the next X_vector and Y_vector pair (e.g. from (3, 15) to (-3, 15). Do I use a continue function to this?
Thank you in advance for your help!

采纳的回答

Voss
Voss 2023-3-6
Maybe this:
for k = 1 : numel(X_vector)
for n = 1 : 5
x = X_vector(k);
y = Y_vector(k);
% Now use x and y in some way.
end
end
  6 个评论
HumbleCoder
HumbleCoder 2023-3-9
The error was on my end!! Thank you so much for helping me!! Your suggestion works like a charm!
Voss
Voss 2023-3-9
You're welcome! Glad you got it to work!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by