How to create a For loop for a linspace?

30 ビュー (過去 30 日間)
Michela Longhi
Michela Longhi 2017 年 6 月 28 日
コメント済み: Star Strider 2017 年 6 月 28 日
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

採用された回答

Star Strider
Star Strider 2017 年 6 月 28 日
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 件のコメント
Michela Longhi
Michela Longhi 2017 年 6 月 28 日
Yes!!!! It's now working. Thank you to all.
Star Strider
Star Strider 2017 年 6 月 28 日
Our pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by