dsearchn() Command is slowing down my algorithm, Any better Solution? MATLAB
Mostra commenti meno recenti
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 Commenti
Bruno Luong
il 26 Ott 2018
Yeah of course, almost anything else is better, why on earth are you using DSEARCHN for numbers? Use INTERP1 with 'nearest' option.
Shahab Khan
il 26 Ott 2018
Bruno Luong
il 26 Ott 2018
Modificato: Bruno Luong
il 26 Ott 2018
Other way around: first you give us a (small) example.
Shahab Khan
il 26 Ott 2018
Modificato: Shahab Khan
il 26 Ott 2018
Bruno Luong
il 27 Ott 2018
You give a piece of code, without telling the size the class of your Data. No one can run your code if copy/past in MATLAB. Almost useless for people who tries to answer the question.
An "example" is some extra instruction to generate a small piece data, (and eventually an expecting output if the code is buggy and does not produce what you expect).
Shahab Khan
il 27 Ott 2018
Bruno Luong
il 27 Ott 2018
Modificato: Bruno Luong
il 27 Ott 2018
Replace
dsearchn(Data(:,1), Distance2)
by
interp1(Distance1,Distance2,'nearest');
Shahab Khan
il 27 Ott 2018
Shahab Khan
il 27 Ott 2018
Bruno Luong
il 27 Ott 2018
Modificato: Bruno Luong
il 27 Ott 2018
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');
Shahab Khan
il 27 Ott 2018
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!