Plot doesn't show in figure

2 次查看(过去 30 天)
Sabine
Sabine 2016-12-16
编辑: Stephen23 2016-12-16
Hello,
For my study I need to learn to work with MatLab and we just started using for loop. Now I tried making a diagram with volume at the x-axis and pressure at the y-axis, using XSteam.
T_iso=[400, 600, 800] %vector with isotherms
for T=T_iso
for i = (1:1:15) %assignment told to use i for pressure (pressure in MPa)
v=XSteam('v_pT', i, T) %calculating v, using XSteam
end
plot(v,i) %trying to plot
end
Everything goes well, until I try to plot this. I do get a figure window with the right values on both the axes, but it does not show any lines or something. Does anyone know how to solve this? Thanks a lot!
Sabine

回答(1 个)

Stephen23
Stephen23 2016-12-16
编辑:Stephen23 2016-12-16
The plot does not show anything because you are not actually plotting anything. You need to use indexing in the loop to store the values that are being calculated, otherwise they will simply get overwritten, and when you go to plot there is nothing to plot. Try this:
I_vec = 1:15;
T_iso = [400,600,800]; % isotherms
% preallocate output matrix:
out = NaN(numel(I_vec),numel(T_iso));
% loop over input vectors:
for ix = 1:numel(I_vec)
for tx = 1:numel(T_iso)
out(ix,tx) = XSteam('v_pT', I_vec(ix), T_iso(tx));
end
end
%
plot(out)
Sadly the author of XSteam did not vectorize their code, or otherwise allow array inputs. If they had it would be possible to get rid of the loops alltogether.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by