Looking for a way to copy an IGOR Pro function in MatLab
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
T-800
el 29 de Jul. de 2022
Comentada: Star Strider
el 1 de Ag. de 2022
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 comentarios
Respuesta aceptada
Star Strider
el 29 de Jul. de 2022
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
