How can I vectorize this find function?

1 visualización (últimos 30 días)
J J
J J el 20 de Nov. de 2018
Comentada: Rena Berman el 22 de Jul. de 2020
for i=1:length(x)
ind_1 = find(b <x(i), 1, 'last');
ind_2 = ind_1+1;
x1 = b(ind_1);
x2 = b(ind_2);
y1 = a(ind_1);
y2 = a(ind_2);
y(i) = (y2-y1)/(x2-x1)*(x(i)-x1) + y1;
end
where b =
0
2.49999993684469e-06
4.99999987368938e-06
7.49999981053406e-06
9.99999974737875e-06
1.24999996842234e-05
1.49999996210681e-05
1.74999986484181e-05
1.99999994947575e-05
2.25000003410969e-05
a = -3.90885305404663
-3.90826201438904
-3.90855741500855
-3.90796637535095
-3.90885305404663
-3.90855741500855
-3.90826201438904
-3.90826201438904
-3.90767097473145
-3.90826201438904
x = 0.500000000000000
1
1.50000000000000
2
2.50000000000000
3
3.50000000000000
4
4.50000000000000
5
  3 comentarios
Rik
Rik el 26 de Jun. de 2020
Editada: Rik el 26 de Jun. de 2020
Original question retrieved from Google cache, as posted by doyi joo:
for i=1:length(x)
ind_1 = find(b <x(i), 1, 'last');
ind_2 = ind_1+1;
x1 = b(ind_1);
x2 = b(ind_2);
y1 = a(ind_1);
y2 = a(ind_2);
y(i) = (y2-y1)/(x2-x1)*(x(i)-x1) + y1;
end
where
b =
0
2.49999993684469e-06
4.99999987368938e-06
7.49999981053406e-06
9.99999974737875e-06
1.24999996842234e-05
1.49999996210681e-05
1.74999986484181e-05
1.99999994947575e-05
2.25000003410969e-05
a = -3.90885305404663
-3.90826201438904
-3.90855741500855
-3.90796637535095
-3.90885305404663
-3.90855741500855
-3.90826201438904
-3.90826201438904
-3.90767097473145
-3.90826201438904
x = 0.500000000000000
1
1.50000000000000
2
2.50000000000000
3
3.50000000000000
4
4.50000000000000
5
Rena Berman
Rena Berman el 22 de Jul. de 2020
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 20 de Nov. de 2018
Editada: Matt J el 20 de Nov. de 2018
y=interp1(b,y_acc,x)
  2 comentarios
Rik
Rik el 20 de Nov. de 2018
(reposted as a new question)
Rik
Rik el 26 de Jun. de 2020
Now deleted comment posted by doyi joo on 20 Nov 2018:
Hey,
Would you be able to help me vectorize this function as well......
%% Find Threshold (y = 2) Points on Rising Edge
for i=1:length(t_pks)-1
ind_y = find(t_raw < t_pks(i+1)& t_raw>t_pks(i));
threshold_pt = find(y_raw(ind_y)<2,1,'last');
x0 = threshold_pt;
y1(i) = y_raw(ind_y(x0));
x1(i) = t_raw(ind_y(x0));
y2(i) = y_raw(ind_y(x0)+1);
x2(i) = t_raw(ind_y(x0)+1);
y(i) = 2;
x(i) = (y(i)-y1(i))*(x2(i)-x1(i))/(y2(i)-y1(i)) + x1(i);
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by