Effacer les filtres
Effacer les filtres

Plot doesn't show in figure

2 vues (au cours des 30 derniers jours)
Sabine
Sabine le 16 Déc 2016
Modifié(e) : Stephen23 le 16 Déc 2016
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

Réponses (1)

Stephen23
Stephen23 le 16 Déc 2016
Modifié(e) : Stephen23 le 16 Déc 2016
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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by