Identifying position in array nearest to a value
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
First time on MATLAB Answers so apologies if I miss anything in my question.
I am carrying out peak fitting on a set of data and would like to identify the left and right points nearest to a line as shown in the figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288922/image.png)
The line is a yline positioned halfway between the height limits of the data set (0.5*(maxy+miny)). I need to extract the data set peak width at this height but none of the array values are equal to this height value so I can't use the idx = X==height; function to find the left and right values of x.
[a1a,b1a] = max(y);
d1a = min(y);
q1a = 0.5*(a1a+d1a);
idx = y==q1a;
Instead, I was hoping to find the index position of the values nearest to the line but I am unsure how to go about doing this.
Any advice would be appreciated!
Thanks
0 Kommentare
Antworten (2)
Eva-Maria Weiss
am 30 Apr. 2020
Hi
I hope I have here some ideas that might help you:
You could try something like zerocrossing, but instead of zero, you look for crossing the y-value;
make a logical condition like
logic = x >= y;
you get a logical vector with length of x, each position thats corresponding value is under y is 0 and above is 1;
Now you could use the diff function,
crossing = diff(logic)
The position where x crosses y then indicated as a 1, the position when the data x cross y line again is -1; all other positions are then 0;
Now you can get the index with the find function:
x1 = find(crossing == 1)
x2 = find(crossing == -1)
Good luck!
0 Kommentare
KSSV
am 30 Apr. 2020
You can get the intersection point of the line and curve, you can use this
to find the intersection between two cruves.
You can find the nesrest points to a give point using knnsearch.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!