Got Questions? Get Answers.
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

Thread Subject:
Help on fixing error

Subject: Help on fixing error

From: Diego Zegarra

Date: 18 Feb, 2009 18:53:01

Message: 1 of 4

??? Error using ==> sub2ind at 58
Out of range subscript.

Error in ==> EF4SAPSLMETARAPS at 351
                    EijF(sub2ind(size(EijF), Eij_CM(:,1:end-1), Eij_CM(:,2:end)))=...
                    EijF(sub2ind(size(EijF), Eij_CM(:,1:end-1), Eij_CM(:,2:end))) + (1/S(s))/E_B;

Sometimes it work and sometimes it shows this error. What does it mean?

Thanks!
                    

Subject: Help on fixing error

From: us

Date: 18 Feb, 2009 19:59:02

Message: 2 of 4

"Diego Zegarra"
> ??? Error using ==> sub2ind at 58
> Out of range subscript.
> Error in ==> EF4SAPSLMETARAPS at 351
> EijF(sub2ind(size(EijF), Eij_CM(:,1:end-1), Eij_CM(:,2:end)))=...
> EijF(sub2ind(size(EijF), Eij_CM(:,1:end-1), Eij_CM(:,2:end))) + (1/S(s))/E_B;
>
> Sometimes it work and sometimes it shows this error. What does it mean...

as the error message clearly says: the inputs to SUB2IND cannot(!) give a valid result, in particular, if one looks at your vars

     size(EijF)
     Eij_CM(:,1:end-1) % one or more indices > size(...,1)
     Eij_CM(:,2:end) % one or more indices > size(...,2)

since this does not happen regularly, you might consider doing this

% at the command prompt
     dbstop if error
% run your function
% if an error occurrs, it will stop in the current function/ws
% now carefully inspect your vars

us

Subject: Help on fixing error

From: Diego Zegarra

Date: 18 Feb, 2009 21:47:01

Message: 3 of 4

Ok I found what the error was but I am having trouble solving it, the thing is before this lines I use the PADCAT function to change a cell of different dimensions into a matrix form where the spaces are padded by zeros or NaN if wanted. The thing is that whenever it pads the matrix then it finds a zero and that is a number I dont want to look at. So let's say I have the following cell,

a={[5 4 1 7];[6 2 3]};
It will change it to look like this,

a=
5 4 1 7
6 2 3 0

or

5 4 1 7
6 2 3 NaN

E = zeros(7);
E(sub2ind(size(E), a(:,1:end-1), a(:,2:end)))

Since 0 is not considered in E then it shows the error because there is no row or column with that index in E.

Any idea how this could be done?

Thanks!

Subject: Help on fixing error

From: Diego Zegarra

Date: 18 Feb, 2009 21:48:02

Message: 4 of 4

Ok I found what the error was but I am having trouble solving it, the thing is before this lines I use the PADCAT function to change a cell of different dimensions into a matrix form where the spaces are padded by zeros or NaN if wanted. The thing is that whenever it pads the matrix then it finds a zero and that is a number I dont want to look at. So let's say I have the following cell,

a={[5 4 1 7];[6 2 3]};
It will change it to look like this,

a=
5 4 1 7
6 2 3 0

or

5 4 1 7
6 2 3 NaN

E = zeros(7);
E(sub2ind(size(E), a(:,1:end-1), a(:,2:end)))

Since 0 is not considered in E then it shows the error because there is no row or column with that index in E.

Any idea how this could be done?

Thanks!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us