How to create a For loop for a linspace?
44 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!