필터 지우기
필터 지우기

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.

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by