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

6 次查看(过去 30 天)
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by