필터 지우기
필터 지우기

No curve in plot when executing function with multiple data sets

조회 수: 2 (최근 30일)
Max Kennedy Till
Max Kennedy Till 2019년 9월 30일
답변: Jyotsna Talluri 2019년 10월 3일
So I have a function to output a value of heat capacity for a given species and temperature.
function[c]=HeatCapacity(Species,T)
if Species == 1
a = 38.91; b = 3.903e-2; c = -3.105e-5; d = 8.606e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 2
a = 48.50; b = 9.188e-2; c = -8.540e-5; d = 32.40e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 3
a = 29.10; b = 1.158e-2; c = -0.607e-5; d = 1.311e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
if Species == 4
a = 29.00; b = 0.2199e-2; c = -0.5723e-5; d = -2.871e-9;
Cp = [d c b a];
HeatCapacity = polyval(Cp,T)
end
% Cp = a + b*T + c*T^2 + d*T^3
And so I want to write a script that plots dependencies of heat capacity for all four species versus temperature in the temperature range ‐100ºC <= T <= 1000ºC in a single plot
for Species = 1:4
T = -100:1:1000
HeatCapacity(Species,T);
plot(T,HeatCapacity(Species,T))
xlim([-100,1000])
ylim([0,100])
end
However this returns a blank plot with no curves. How can I fix this in order to display the four curves?

답변 (1개)

Jyotsna Talluri
Jyotsna Talluri 2019년 10월 3일
The function output variable should be initialized same as the passing variable . For plotting multiple plots on the same curve use hold on and hold off
function Capacity = HeatCapacity(Species,T)
if Species == 1
a = 38.91; b = 3.903e-2; c = -3.105e-5; d = 8.606e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 2
a = 48.50; b = 9.188e-2; c = -8.540e-5; d = 32.40e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 3
a = 29.10; b = 1.158e-2; c = -0.607e-5; d = 1.311e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
if Species == 4
a = 29.00; b = 0.2199e-2; c = -0.5723e-5; d = -2.871e-9;
Cp = [d c b a];
Capacity = polyval(Cp,T)
end
end
figure();
hold on;
for Species = 1:4
T = -100:1:1000
c=HeatCapacity(Species,T);
plot(T,c)
xlim([-100,1000])
ylim([0,100])
end
hold off

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by