Graphing an array so the largest row graphs first and then so forth

I have an x and y array, let's say the x-array is: (1,8,15,NaN,NaN; 1,8,15,22,29; 1,8,15,22,NaN), and the y-array is: (0,0,0,NaN,NaN; 0,0,0,2,2; 0,0,0,0,NaN). I would like to graph these two arrays so that the row vector with the longest length is graphed first, and then so on and so on. This is because when I am graphing these arrays right now, the first y-vector gets 'overwritten' by the next two y-vectors and I can't see the line at all. How do I fix this?

댓글 수: 1

As you can see in this picture, the blue line for 'G5 FS6' is not shown because the yellow line is plotted after it.

댓글을 달려면 로그인하십시오.

 채택된 답변

DGM
DGM 2023년 4월 26일
편집: DGM 2023년 4월 26일
Maybe something like
x = [1,10,15,NaN,NaN; 1,10,15,20,25; 1,10,15,20,NaN];
y = [0,0,1,NaN,NaN; 0,0,0,0,3; 0,0,0,2,NaN];
% get index vector
[~,idx] = sort(sum(~isnan(x),2),'descend');
% plot
plot(x(idx,:).',y(idx,:).','linewidth',3)
But bear in mind that this just sorts by the number of non-NaN entries. It doesn't test to see where the non-NaN segments overlap

추가 답변 (1개)

Matt J
Matt J 2023년 4월 26일
편집: Matt J 2023년 4월 26일
IMHO, it's better just to assign distinct markers:
x=[1,8,15,NaN,NaN; 1,8,15,22,29; 1,8,15,22,NaN];
y=[0,0,0,NaN,NaN; 0,0,0,2,2; 0,0,0,0,NaN];
H=plot(x',y'); axis padded
[H.MarkerSize]=deal(6,10,14);
[H.Marker]=deal('x','s','o');

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

2023년 4월 26일

댓글:

2023년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by