Looking for a way to copy an IGOR Pro function in MatLab

조회 수: 3 (최근 30일)
T-800
T-800 2022년 7월 29일
댓글: Star Strider 2022년 8월 1일
In Igor pro there is a function called findLevel. Essentially what it does is locate the x coordinate at which the data either passes through or reaches a given y value. In my case my y axis is acceleration and my x axis is time in seconds and I am trying to find all time points wherein the acceleration reaches or passes through the value y=150. However, I haven't found a way to replicate this in MatLab. I've tried using the Interp1 function but this didn't work (possibly because none of the acceleration values are exactly 150?). I was hoping someone might be aware of a way to attack this. Any input would be appreciated.

채택된 답변

Star Strider
Star Strider 2022년 7월 29일
You can do something similar with something like this (that I have turned into a funciton) —
x = linspace(0, 10*pi, 250);
y = sin(x) + linspace(-2, 2, numel(x));
level = 1.5;
xv = FindLevel(x, y, level);
figure
plot(x, y)
hold on
plot(xv, ones(size(xv))*level, 'rs')
hold off
grid
function xv = FindLevel(x,y,level)
cxi = find(diff(sign(y-level)));
for k = 1:numel(cxi)
idxrng = max(1,cxi(k)-1) : min(numel(x), cxi(k)+1);
xv(k) = interp1(y(idxrng), x(idxrng), level);
end
end
The ‘xv’ output of ‘FindLevel’ are the interpolated x-coordinates of the points where the curve equals ‘level’, so they may not be exact points in the ‘x’ vector. Those approximate points (actually indices) are returned by the ‘cxi’ assignment in my function.
.
  댓글 수: 2
T-800
T-800 2022년 8월 1일
It works like a charm. Many Appreciations!
Star Strider
Star Strider 2022년 8월 1일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by