dsearchn() Command is slowing down my algorithm, Any better Solution? MATLAB

3 次查看(过去 30 天)
I am using the following code to calculate altitude.
Data = [Distance1',Gradient];
Result = Data(dsearchn(Data(:,1), Distance2), 2);
Altitude = -cumtrapz(Distance2, Result)/1000;
Distance 1 and Distance 2 has different size with same values so I am comparing them to get corresponding value of Gradient to use with Distance 2.
Just to execute these 3 lines the Matlab takes 12 to 15 seconds. Which slow down my whole algorithm.
Is there any better way I can perform above action without slowing down my algorithm?
  11 个评论
Bruno Luong
Bruno Luong 2018-10-27
编辑:Bruno Luong 2018-10-27
I wrote replace just the DSEARCH, not the rest.
If you want to get the same Result as with
Data = [Distance1',Gradient];
Result = Data(dsearchn(Data(:,1), Distance2), 2);
and Data is just temporary variable and you don' mind to trash it away after, then
Result = interp1(Distance1,Gradient,Distance2,'nearest');

请先登录,再进行评论。

采纳的回答

Bruno Luong
Bruno Luong 2018-10-27
编辑:Bruno Luong 2018-10-27
Replace
dsearchn(Data(:,1), Distance2)
by
interp1(Distance1,Distance2,'nearest');
If you want to get the same Result as with
Data = [Distance1',Gradient];
Result = Data(dsearchn(Data(:,1), Distance2), 2);
and Data is just temporary variable and you don' mind to trash it away after, then
Result = interp1(Distance1,Gradient,Distance2,'nearest');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by