How do I break the line for every 50th row in a matrix
조회 수: 1 (최근 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!