How to: Merging multiple graph lines
조회 수: 34 (최근 30일)
이전 댓글 표시
Hello Guys,
my problem is that I have several data sets of different x-Arrays and always the same y-Array. Basically my plot functions looks like this: plot(x1,y,'g',x2,y,'b'....)
As I have drawn in the picture I want to merge all the lines as to always keep the lowest y-values going from left to right in terms of x-values. This should creat one single new plot that looks like the black line in the right picture. The left picture demonstrates the overlapping data sets.
Can I solve this problem graphically, e.g. using a plotting function to always display the lowest y-value or do I need to create a new 2D array that always picks the lowest y-value for every x- value? Maybe you can give me a base to start from. Sorry about my "untechnical" explanation, Im new to Matlab and coding in general.
Thanks in advance for your support. Pat
댓글 수: 2
Guillaume
2014년 10월 18일
It looks like you meant to attach or (better) embed a figure, but seems like you forgot
채택된 답변
Guillaume
2014년 10월 20일
편집: Guillaume
2014년 10월 20일
I would concatenate all your x, get the unique values and their position and use the position with accumarray to get the minimum of y:
xall = [x1 x2 x3 ...];
[x, ~, indices] = unique(xall);
y = accumarray(indices, repmat(y, 1, N)', [], @min); %where N is the number of xi
plot(x, y);
edited for missing comma
추가 답변 (1개)
Rick Rosson
2014년 10월 18일
x = [ x1 x2 x3 ... ];
N = length(x)/length(y);
y = repmat(y,1,N);
plot(x,y);
댓글 수: 2
vi trung kien
2018년 3월 21일
편집: vi trung kien
2018년 3월 21일
Dear Patrick, Can you suggest for me how to get one single united line that always displays Ymin(n), like you have scratched in the pictures attached.My problem the same as you before. Thanks for your help.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!