Matrix having one row
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Rostislav Stanek
am 15 Sep. 2020
Kommentiert: Rostislav Stanek
am 15 Sep. 2020
Hello,
I have the following problem: I would like to create a vecor of vectors containing pairs of numbers and then iterate through it. If I have a vector containing more than one pair, everything is OK:
x = [[-2, -1.5]; [-0.5, 0.5]; [2, 2.5]];
for i = 1:length(x)
%operations with x(i)
end
Unfortunately, if the input is a vactor containing only one pair, the program crashes:
x = [[-2, -1.5]];
for i = 1:length(x)
%operations with x(i)
end
I understand, why the program crashes, but I do not know, how to solve it. With other words: How can I design a general program, which works for both possibility without necessity of changing the loop?
Thank you for your help!
Rostislav
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 15 Sep. 2020
Bearbeitet: Bruno Luong
am 15 Sep. 2020
Avoid using LENGTH
Replace with
for i = 1:size(x,1)
...
end
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming 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!