How can I vectorize this find function?

2 visualizzazioni (ultimi 30 giorni)
J J
J J il 20 Nov 2018
Commentato: Rena Berman il 22 Lug 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 Commenti
Rik
Rik il 26 Giu 2020
Modificato: Rik il 26 Giu 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 il 22 Lug 2020
(Answers Dev) Restored edit

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 20 Nov 2018
Modificato: Matt J il 20 Nov 2018
y=interp1(b,y_acc,x)
  2 Commenti
Rik
Rik il 20 Nov 2018
(reposted as a new question)
Rik
Rik il 26 Giu 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by