How to create a For loop for a linspace?

40 visualizaciones (últimos 30 días)
Michela Longhi
Michela Longhi el 28 de Jun. de 2017
Comentada: Star Strider el 28 de Jun. de 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

Respuesta aceptada

Star Strider
Star Strider el 28 de Jun. de 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 comentarios
Michela Longhi
Michela Longhi el 28 de Jun. de 2017
Yes!!!! It's now working. Thank you to all.
Star Strider
Star Strider el 28 de Jun. de 2017
Our pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by