Why F vs T graph are not plotted , it shows only blank figure and how i can get all the values of F and T in the workspace as it shows only last value.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sarvjeet Singh
am 27 Sep. 2020
Kommentiert: Sarvjeet Singh
am 4 Okt. 2020
c1 = 27.742*10.^8;
c2 = 1.43878*10.^4;
sigma = 5.67*10.^-8;
T = 5780;
lamda_1 = 8;
lamda_2 = 13;
for T=-10:5:30
fun = @(lambda) c1./lambda.^5.*(exp(c2./(lambda * T+273))-1);
F = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4)
plot(T,F)
hold on
grid
end
xlabel('Temperature')
ylabel('Fraction in atmospheric window)')
title('Fraction of the radiation emitted in the atmospheric window as a function of temperature')
legend('T=-10','T=-5','T=0','T=5','T=10','T=15','T=20','T=25','T=30')
hold off
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 27 Sep. 2020
You are not specifying the marker type in plot() and also you are not saving vaues of F at each iteration
c1 = 27.742*10.^8;
c2 = 1.43878*10.^4;
sigma = 5.67*10.^-8;
lamda_1 = 8;
lamda_2 = 13;
Tv = -10:5:30;
F = zeros(size(Tv));
count = 1;
for T=Tv
fun = @(lambda) c1./lambda.^5.*(exp(c2./(lambda * T+273))-1);
F(count) = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4);
plot(T, F(count), '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
grid
count = count + 1;
end
xlabel('Temperature')
ylabel('Fraction in atmospheric window)')
title('Fraction of the radiation emitted in the atmospheric window as a function of temperature')
legend('T=-10','T=-5','T=0','T=5','T=10','T=15','T=20','T=25','T=30')
hold off
Weitere Antworten (1)
Walter Roberson
am 27 Sep. 2020
for T=-10:5:30
Inside the body of the for loop, at any one time, T will be a scalar value. The first iteration it would be the scalar value -10, the second time it would be the scalar value -5, and so on.
F = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4)
The result of integral() is always a scalar, unless you have passed in the option 'ArrayValued', true
plot(T,F)
so there you are plot() with a scalar T and scalar F. But by default, plot() is only for drawing lines, and in order to draw a line, plot needs to be be passed something that includes at least two adjacent finite values. With scalar T and scalar F, there is only the one point, when it needs at least two points to join to create a line.
plot() does not "remember" the previous points that have already been drawn to automatically join them together -- that would typically be the wrong thing to do.
There are several different things you can do:
- you can plot(T, F, '*') which will not create any lines, but will at least put a * marker at every point
- you can keep a record of each T and F value, storing the values inside vectors inside the loop, and then plot afterwards with no plot inside the loop. I recommend that you read https://www.mathworks.com/matlabcentral/answers/504285-for-loop-for-non-consecutive-values-in-an-array#answer_414399
- you can keep track of the handle of the "chart line object" (line()) that plot() outputs, and then each iteration of the loop, pull out the XData and YData properties of that line() object, and add the new T and F point to the ends of those lists, and set those as the new values for the XData and YData properties. The line() object is the internal representation of which points are to be drawn, so updating the XData and YData properties would cause it to extend the existing line
- you can use animatedline() and addpoints() to hide the details of the kind of XData / YData tracking that I mentioned above.
Except for very long loops where you want to see plotting results before the function finishes, I recommend taking the approach of recording the values and plotting afterwards.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!