How to plot a 2D graph using for loop values?
古いコメントを表示
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 日
編集済み: Joseph Cheng
2015 年 6 月 3 日
Whats wrong with it and why is the plot not what you're looking for? the code matches what the plot should be.
also no need for the for loop as
if true
lambda= [1.5:0.005:1.6];
k=2*3.14./lambda;
plot(lambda,k);
end
accomplishes the same thing
sha
2015 年 6 月 3 日
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)?
jyoti mishra
2018 年 2 月 20 日
0 投票
how to plot a vector and its delayed version in matlab?
1 件のコメント
Image Analyst
2018 年 2 月 20 日
Try using the plot() function.
カテゴリ
ヘルプ センター および File Exchange で Graphics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!