Which MATLAB operations/functions need speeding up?
Réponses (23)
2 commentaires
- 11/20, 5:00PM EST - Added comment about OOP.
- 11/20, 5:10PM EST - Added comment about TRY statements.
- 11/21, 8:50AM EST - Added comment about documentation.
2 commentaires
0 commentaires
0 commentaires
2 commentaires
5 commentaires
6 commentaires
3 commentaires
0 commentaires
4 commentaires
7 commentaires
1 commentaire
2 commentaires
Matrix indexing needs speeding up.
For a very simple example, if I run this:
clear; clc; close all; N1=100; N2=100; A=(ones(N1,N2,'single')); C=(ones(N1,N2,'single')); tic; for i=1:1e4 %C(2:end,:)=C(2:end,:)-A(1:end-1,:); C=C-A; end toc;
I got Elapsed time is 0.056711 seconds.
Instead if I run the following:
clear; clc; close all; N1=100; N2=100; A=(ones(N1,N2,'single')); C=(ones(N1,N2,'single')); tic; for i=1:1e4 C(2:end,:)=C(2:end,:)-A(1:end-1,:); %C=C-A; end toc;
I got: Elapsed time is 0.316735 seconds.
That is to say the most of the time Matlab is just doing the matrix indexing, Is there any way to improve this or avoid the indexing but get the same result? This could make my code almost 10 times faster!
11 commentaires
@Hao Zhang: SHAREDCHILD will not work with non-contiguous sub-arrays, and should generate an error if you try. E.g.,
>> A = reshape(1:12,3,4) A = 1 4 7 10 2 5 8 11 3 6 9 12 >> A(1:end-1,:) ans = 1 4 7 10 2 5 8 11 >> sharedchild(A,[1 inf],[-1 inf]) ??? Error using ==> sharedchild Indexing must be contiguous
Do you have a case where SHAREDCHILD did not generate an error for a non-contiguous sub-array? If so, this is a bug that needs to be fixed.
The R2018a mex situation is much worse that I thought ...
persistent statement
Not sure the reason (internal data hashing?) , but it is slow.
0 commentaires
Voir également
Catégories
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!