How can I vectorize this find function?

1 vue (au cours des 30 derniers jours)
J J
J J le 20 Nov 2018
Commenté : Rena Berman le 22 Juil 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 commentaires
Rik
Rik le 26 Juin 2020
Modifié(e) : Rik le 26 Juin 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 le 22 Juil 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 20 Nov 2018
Modifié(e) : Matt J le 20 Nov 2018
y=interp1(b,y_acc,x)
  2 commentaires
Rik
Rik le 20 Nov 2018
(reposted as a new question)
Rik
Rik le 26 Juin 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by