Looking for a way to copy an IGOR Pro function in MatLab
조회 수: 3 (최근 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.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
