Plot marker on points not specified within the vector
Mostrar comentarios más antiguos
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 comentario
David Hill
el 27 de Ag. de 2020
Sounds like you need to fit the data, look at fit() funciton.
Respuesta aceptada
Más respuestas (1)
KSSV
el 28 de Ag. de 2020
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')
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

