Effacer les filtres
Effacer les filtres

How to create a For loop for a linspace?

14 vues (au cours des 30 derniers jours)
Michela Longhi
Michela Longhi le 28 Juin 2017
Commenté : Star Strider le 28 Juin 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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by