How do I break the line for every 50th row in a matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Petter Gjerstad
am 9 Okt. 2019
Kommentiert: Petter Gjerstad
am 9 Okt. 2019
Hi,
I have a large matrix (A) of different variables, 2500 rows and 3 columns (actually 15, but I only need the 3).
I have a constant pressure with increasing temperature, 273K - 290K (50 rows) before it returns to the 273K again but this time with a higher constant pressure.
So for every 50th rows, I need it to stop drawing a line between the data points(290 back to the 273), this is because it looks likes it is a part of the function(the top layer)

load A
x = A(1:50:end,1); %temperatur
y = A(1:50:end,2); %Pressure
z = A(1:50:end,5); %Molefraction
figure
plot3(x,y,z)
grid on
ax.ZGrid = 'off';
ax.XGrid = 'on';
ax.YGrid = 'on';
xlabel('Temperature (K)')
ylabel('Pressure (bars)')
zlabel('Liquid mole fraction CH_4')

This is what I end up with by using the code I wrote above. I have been trying for hours, and I know it should be straightforward, but I'm used to do only simple plotting in MatLab.
If anyone can help me, it will make my day a lot better :)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Okt. 2019
Bearbeitet: Walter Roberson
am 9 Okt. 2019
Atemp = reshape(A, 50, [], size(A,2));
Atemp(end+1,:,:) = nan;
Apadded = reshape(Atemp, [], size(A,2));
x = Apadded(:,1);
y = Apadded(:,2);
z = Apadded(:,3);
The idea here is that plot() and plot3() stop drawing when they encounter a nan.
Weitere Antworten (1)
Daniel M
am 9 Okt. 2019
Fairly simple. Just need to reshape the variables. Here is an example:
d = 10;
x = repmat(1:d,1,d)';
y = [sin(x)];
t = 1:length(x);
% this is what your plot currently looks like
figure
plot3(t,x,y)
% reshape vectors
xx = reshape(x,d,[]);
yy = reshape(y,d,[]);
tt = reshape(t,d,[]);
% this is what you want it to look like
figure
plot3(tt,xx,yy,'b')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!