How do I break the line for every 50th row in a matrix

1 visualización (últimos 30 días)
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)
fail.bmp
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')
untitled.bmp
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 :)

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Oct. de 2019
Editada: Walter Roberson el 9 de Oct. de 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.

Más respuestas (1)

Daniel M
Daniel M el 9 de Oct. de 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')

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by