How can I vectorize this find function?

1 Ansicht (letzte 30 Tage)
J J
J J am 20 Nov. 2018
Kommentiert: Rena Berman am 22 Jul. 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 Kommentare
Rik
Rik am 26 Jun. 2020
Bearbeitet: Rik am 26 Jun. 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 am 22 Jul. 2020
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 20 Nov. 2018
Bearbeitet: Matt J am 20 Nov. 2018
y=interp1(b,y_acc,x)
  2 Kommentare
Rik
Rik am 20 Nov. 2018
(reposted as a new question)
Rik
Rik am 26 Jun. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by