Storing function outputs to an array so they can be plotted

Hi,
Im new to MATLAB and am trying to get a for loop to save a range of outputted values so that i can then plot them against data i already have (Lambda). Any help would be greatly appreciated as im at a loss.
Currently my code only saves 1 value for A and 1 value for I.
my code is;
for A= 1,1:20;
H_l = 2*(A+1);
Sig_Lambda = 1*10^-9;
I = A*H_l*Sig_Lambda
end
plot(Lambda,I)

댓글 수: 1

I think there is a syntax error in your loop counter. Should it be this?
for A=1:1:20

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

 채택된 답변

Torsten
Torsten 2022년 1월 8일
편집: Torsten 2022년 1월 8일
A = 1:20;
H_l = 2*(A+1);
Sig_Lambda = 1*10^-9;
I = A.*H_l*Sig_Lambda;
plot(Lambda,I)
works if Lambda is a sorted 1x20 vector.

댓글 수: 1

Thank you very much, i fixed my Lambda vector and got rid of the for loop and it works now. :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2022년 1월 8일

댓글:

2022년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by