# Which MATLAB operations/functions need speeding up?

### Risposte (23)

##### 2 Commenti

- 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 Commenti

##### 0 Commenti

##### 0 Commenti

##### 2 Commenti

##### 5 Commenti

##### 6 Commenti

##### 3 Commenti

##### 0 Commenti

##### 4 Commenti

##### 7 Commenti

##### 1 Commento

##### 2 Commenti

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 Commenti

@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 Commenti

### Vedere anche

### Categorie

### Prodotti

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!