How to plot a 2D graph using for loop values?

조회 수: 3 (최근 30일)
sha
sha 2015년 6월 3일
댓글: Image Analyst 2018년 2월 20일
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
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?
sha
sha 2015년 6월 3일
편집: sha 2015년 6월 3일
If I run the code, the following errors appear:
Error using plot Vectors must be the same lengths.
Error in Untitled7 (line 7) plot(lambda,k);
How to fix this error?

댓글을 달려면 로그인하십시오.

채택된 답변

sha
sha 2015년 6월 3일
Thanks, Cheng. I would like to plot the same thing, however. using for loop. Just curious how to plot the data using for loop? Could you help?

추가 답변 (2개)

Image Analyst
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
jyoti mishra 2018년 2월 20일
how to plot a vector and its delayed version in matlab?

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by