Which MATLAB operations/functions need speeding up?
回答(23 个)
2 个评论
- 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 个评论
0 个评论
0 个评论
2 个评论
5 个评论
6 个评论
3 个评论
0 个评论
4 个评论
7 个评论
1 个评论
2 个评论
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 个评论
@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 个评论
另请参阅
类别
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!