using for loop with 2 variables.
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sermet
am 6 Mai 2014
Beantwortet: Mischa Kim
am 6 Mai 2014
a=[1;2;3;4]
b=[5;6;7]
for i=1:4
for j=1:3
x=a(i)+b(j)
end
end
% it gives 12 x but I cannot merge all x(i) like that:
x=[6;7;8;7;8;9;8;9;10;9;10;11] %[x(1);x(2);x(3);......x(12)]
0 Kommentare
Akzeptierte Antwort
Mischa Kim
am 6 Mai 2014
Sermet, use
a = [1;2;3;4]
b = [5;6;7]
kk = 1;
for ii = 1:4
for jj = 1:3
x(kk) = a(ii) + b(jj)
kk = kk + 1;
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!