Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Index exceeds matrix dimensions.

Asked by Locks

Locks

on 10 Apr 2013
Accepted Answer by Cedric Wannaz

Cedric Wannaz

hi,

I have used this code here:

for i=1:length(data8(:,1))
if(data8(i,8)>1.1)
data8(i,:) = [];
end
if(data8(i,8)<0.9)
data8(i,:) = [];
end
end

where data 8 is a matrix with 8 columns, and I get this error message:

Index exceeds matrix dimensions.

Error in construct_data (line 43) if(data8(i,8)>1.1)

has anybody an idea why this can happen?

0 Comments

Locks

Locks

Products

No products are associated with this question.

1 Answer

Answer by Cedric Wannaz

Cedric Wannaz

on 10 Apr 2013
Edited by Cedric Wannaz

Cedric Wannaz

on 10 Apr 2013
Accepted answer
 length(data8(:,1))

is evaluated only once at the beginning of the FOR loop. It is e.g. 10. Then you remove rows from data8 , whose size therefore decreases (9 rows, 8 rows, ..). At one point the loop index (that is still incremented until it hits 10) becomes larger than the remaining number of rows in data8.

3 Comments

Locks

Locks

on 10 Apr 2013

is there something I can do that it's dynamic and still running?

Cedric Wannaz

Cedric Wannaz

on 10 Apr 2013

Several ways, one is:

 i = 0 ;
 while i < size(data8, 1)
    i = i + 1 ;
    % .. whatever you have to do.
 end
Locks

Locks

on 10 Apr 2013

great, thanks!

Cedric Wannaz

Cedric Wannaz

Contact us