How can I vectorize this find function?

1 次查看(过去 30 天)
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 个评论
Rik
Rik 2020-6-26
编辑:Rik 2020-6-26
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

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2018-11-20
编辑:Matt J 2018-11-20
y=interp1(b,y_acc,x)
  2 个评论
Rik
Rik 2020-6-26
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

尚未输入任何标签。

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by