Filter löschen
Filter löschen

How to create a For loop for a linspace?

14 Ansichten (letzte 30 Tage)
Michela Longhi
Michela Longhi am 28 Jun. 2017
Kommentiert: Star Strider am 28 Jun. 2017
I have this code:
for j = 1:20
c(j) = linspace(1,10,length(j));
end
But, the result is a vector "c" with all the values "10":
c= 10 10 10 10 10 10 10....
How can I do to solve the problem? Thnaks

Akzeptierte Antwort

Star Strider
Star Strider am 28 Jun. 2017
Since in every iteration, ‘j’ is a scalar, the length of ‘j’ will always be 1.
I would just use:
c = linspace(1, 10, 20);
or if you actually want varying-length vectors, save ‘c’ as a cell array:
for j = 1:20
c{j} = linspace(1,10,j);
end
  5 Kommentare
Michela Longhi
Michela Longhi am 28 Jun. 2017
Yes!!!! It's now working. Thank you to all.
Star Strider
Star Strider am 28 Jun. 2017
Our pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties 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!

Translated by