How to plot a 2D graph using for loop values?
2 次查看(过去 30 天)
显示 更早的评论
Hello, Could anyone tell me what the problem is in the following code?
Many thanks.
% code:
lambda= [1.5:0.005:1.6];
llambda=length(lambda);
for di=1:llambda
k(di)=2*3.14/lambda(di)
end
lambda= [1.5:0.005:1.6];
plot(lambda,k);
4 个评论
Joseph Cheng
2015-6-3
I am trying. The main question is why is the plot in your sample code not what you're trying to get. If it is then what is the question or is the question to plot within the for loop?
采纳的回答
更多回答(2 个)
Image Analyst
2015-6-3
The code works fine:
lambda= [1.5:0.005:1.6];
llambda = length(lambda);
for di = 1 : llambda
k(di) = 2 * 3.14 / lambda(di)
end
plot(lambda,k);
It plots with absolutely no warnings or errors about different lengths. What is the actual code you ran (it's not that , that's for sure)?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!