- To iterate over the values of a single column vector, first transpose it to create a row vector.
How does the matlab for loop work on a column vs. row vector of strings?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
displaying a vector of strings using a for loop gives different results with a column vector vs. a row vector, why is that?
words = ["this"; "is"; "text"]
for word = words
disp(word);
end
for word = words'
disp(word);
end
0 Kommentare
Antworten (1)
Voss
am 2 Nov. 2022
for iterates over columns, so if you give it a column vector, it iterates one time, with the loop variable taking the value of the whole column.
for col = eye(3)
disp(col)
end
Why? Because the powers that be decided that's how it should work.
From the documentation:
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!