Plot marker on points not specified within the vector
古いコメントを表示
Hello, I have a plot made up of two vectors as such:
x = 0:1:11;
y = [0 1 2 3 4 5 4 3 2 1.5 1 0];
My goal is to create a marker on the plot where the y value reaches 75% of the max y value. I know I can find that value as such:
ymax = max(y)
y75 = 0.75*ymax
For my data, this yields a value of 3.75. I would then like to find the correlating x value for 3.75 and then create a marker at that coordinate as stated before.
I was trying to do this using: x75 = find(y75 == y)
However, the problem I have been running into is that matlab can not find the corresponding x value because that value is not specified within my x vector.
Is there a way to do this?
Thank you ahead of time!
1 件のコメント
David Hill
2020 年 8 月 27 日
Sounds like you need to fit the data, look at fit() funciton.
採用された回答
その他の回答 (1 件)
KSSV
2020 年 8 月 28 日
You need to do interpolation frst to get 75% of maximum value.
x = 0:1:11;
y = [0 1 2 3 4 5 4 3 2 1.5 1 0];
%
y75 = 0.75*max(y) ;
% Do interpolation
xi = linspace(min(x),max(x),10^5) ;
yi = interp1(x,y,xi) ;
% get x75 locations
idx = abs(yi-y75)<10^-3;
plot(x,y)
hold on
plot(xi(idx),yi(idx),'*r')
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

