フィルターのクリア

Identifying position in array nearest to a value

6 ビュー (過去 30 日間)
Matthew Stamp
Matthew Stamp 2020 年 4 月 30 日
回答済み: KSSV 2020 年 4 月 30 日
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.
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

回答 (2 件)

Eva-Maria Weiss
Eva-Maria Weiss 2020 年 4 月 30 日
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!

KSSV
KSSV 2020 年 4 月 30 日
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.

タグ

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by