Which MATLAB operations/functions need speeding up?
Antworten (23)
2 Kommentare
- 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 Kommentare
0 Kommentare
0 Kommentare
2 Kommentare
5 Kommentare
6 Kommentare
3 Kommentare
0 Kommentare
4 Kommentare
7 Kommentare
1 Kommentar
2 Kommentare
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 Kommentare
@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 Kommentare
Siehe auch
Kategorien
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!