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)

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 个评论
采纳的回答
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
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')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!