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

2 次查看(过去 30 天)
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 :)

采纳的回答

Walter Roberson
Walter Roberson 2019-10-9
编辑:Walter Roberson 2019-10-9
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.

更多回答(1 个)

Daniel M
Daniel M 2019-10-9
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')

类别

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

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by