Improving performance of interp1 function inside for loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arya
am 23 Aug. 2016
Bearbeitet: Arya
am 24 Aug. 2016
Hello,
I'm looking for some insight on troubleshooting a matlab fcn bottleneck in a Simulink project. According to the code profiler this Matlab in-line function is (understandably) hogging the runtime:
function [preview,preview_a] = fcn(dp,X_matrix,rho_matrix)
%preallocate
rho_matrix_t = rho_matrix'
preview_a=zeros(1,185);
for i=1:dp
preview(i)=X+i;
preview_a(i)=interp1(X_matrix,rho_matrix_t,preview(i));
end
I understand the interp1 will inevitably consume some CPU time, but could there be some approach to improve the above code?
In the meantime I have these following in mind:
- Vectorization: building preview(1:dp) then do interp1 operation in batch (but I suspect interp1 doesn't support this)
- Using other built-in Simulink block that does equivalent jobs? (I've been looking at interp block, will see if it does the job).
Any suggestions are welcomed. :)
Regards,
Arya
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 23 Aug. 2016
interp1() is fine with accepting a vector of points to interpolate at. Building preview ahead of time should work well.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!