How can i add multiple lines in a plot with a variable?

The code that i have is working as intented, but i want to add multiple lines in the same plot where the difference is one variable.
It is the variable "T" that is 5780, but i also want to have it plotted as T=4000, T=3500, T=3000, T=2500 & T=2000, all in the same picture.
Thanks in advance.
T=5780;
x(1)=1.0e-7;
I(1)=0;
I0=3.74177152e-16;
C=1.438776950e-2
for j=2:1000
I(j-1)=I0*(x(j-1)^(-5))/(exp(C/(x(j-1)*T))-1);
I(j-1)=I(j-1)/1.0e9;
I(j-1)=I(j-1)/1.0e4;
x(j)=x(j-1)+2.0e-9;
x(j-1)=x(j-1)*1.0e9;
end
I(1000)=I0*(x(1000)^(-5))/(exp(C/(x(1000)*T))-1);
I(1000)=I(1000)/1.0e9;
I(1000)=I(1000)/1.0e4;
x(1000)=x(1000)*1.0e9;
plot(x,I);
xlabel('-> golflengte (nm)')
str = '$$ -> \Delta I \Delta \lambda^{-1} (10^4 Wm^2nm^{-1})$$';
ylabel(str,'Interpreter','latex')
axis([0 2500 0 10]);

 採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 4 日

0 投票

T = [2000, 2500, 3000, 3500, 4000, 4500, 5000, 5780];
numT = length(T);
x(1)=1.0e-7;
I(1,1:numT) = 0;
I0=3.74177152e-16;
C=1.438776950e-2
C = 0.0144
for j=2:1000
I(j-1,:) = I0*(x(j-1)^(-5))./(exp(C./(x(j-1)*T))-1);
I(j-1,:) = I(j-1,:)/1.0e9;
I(j-1,:) = I(j-1,:)/1.0e4;
x(j)=x(j-1)+2.0e-9;
x(j-1)=x(j-1)*1.0e9;
end
I(1000,:) = I0*(x(1000)^(-5))./(exp(C./(x(1000)*T))-1);
I(1000,:) = I(1000,:)/1.0e9;
I(1000,:) = I(1000,:)/1.0e4;
x(1000)=x(1000)*1.0e9;
plot(x,I);
xlabel('-> golflengte (nm)')
str = '$$ -> \Delta I \Delta \lambda^{-1} (10^4 Wm^2nm^{-1})$$';
ylabel(str,'Interpreter','latex')
axis([0 2500 0 10]);
legend(string(T))

6 件のコメント

Promu
Promu 2021 年 9 月 4 日
Fast and correct! Many thanks!
Promu
Promu 2021 年 9 月 4 日
Cheered a bit to soon, i'm getting this error? Any ideas?
Walter Roberson
Walter Roberson 2021 年 9 月 4 日
Perhaps you did not clear I between the old code and the new code.
Promu
Promu 2021 年 9 月 4 日
Just tried a new file and i am still getting the same error. Do i need to remove some temp file or something? The code and plot you posted is exactly what i mean.
Walter Roberson
Walter Roberson 2021 年 9 月 4 日
clearvars
once before you run the code. I think you have an old I variable in memory.
The output you see above is "live" -- I ran it right in the Answers system itself.
Promu
Promu 2021 年 9 月 4 日
That did the trick! Again, thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 9 月 4 日

コメント済み:

2021 年 9 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by