What is the syntax for iterating over given coordinates, using a For loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mariam Shahab
am 2 Aug. 2022
Beantwortet: Karim
am 2 Aug. 2022
I have the following code:
X1= [10 12 14 23 24 23 18 16 12 10];
Y1= [20 20 18 15 8 7 8 6 12 20];
for i= X1 and j=Y1
%code
end
I need the correct synatx where the For loop is initiated so that both arrays can be used for iteration simutaneously. I will appreciate any advice. Many thanks.
0 Kommentare
Akzeptierte Antwort
Karim
am 2 Aug. 2022
You can do this in the following way:
X1 = [10 12 14 23 24 23 18 16 12 10];
Y1 = [20 20 18 15 8 7 8 6 12 20];
for i = 1:numel(X1)
xi = X1(i);
for j = 1:numel(Y1)
yj = Y1(j);
% code using xi and yj
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!