How does one plot only the maximum y value for an x value with multiple y values?
显示 更早的评论
I have two vectors (y4 and T4) and need to plot y4 on the x-axis and T4 on the y-axis. The only problem is that there exists multiple values of T4 for each value of y4, so how can I only plot the highest of the T4 values for each y4? I have attached my two vectors for reference.
采纳的回答
更多回答(1 个)
Basil C.
2019-7-9
Hi Geoff,
After seeing the data you provided im assuming the data set it something like
y4=[5 5 4 4 3 3 2 2 2];
t4=[1 2 3 4 5 6 7 8 9]; % this is not the actual data but only for better...
% understanding of how I see your problem
And the solution you are searching for is like
y4= [ 5 4 3 2]
answer= [ 2 4 6 9] % the maximum value of each t4 for a unique y4 value
Then the below solution should help you
N = diff([0 find(diff(y4)) numel(y4)]) %NOTE y4 should be a horizontal vector
answer=[];
for i=1:numel(N)
s=sum(N(1:i));
k=T4(s-N(i)+1:s);
answer=[answer,max(k)];
end
Y4=unique(y4)
answer
类别
在 帮助中心 和 File Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
