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:
Matrix indices

Subject: Matrix indices

From: rahill

Date: 29 Jan, 2012 10:23:52

Message: 1 of 8

Hi every body
I have one section in my function that produces matrix indices and
then I reshape my matrix according to those Indices.
OneColumnIndex=bsxfun(@plus,(1:ll).',11250.*(0:n_cut-1));
ColumnsIncrements=reshape ((0:RChunk-1).*180000,1,1,[]);
AllColumns=bsxfun(@plus,oneColumnIndex,ColumnIncrements);
AllColumns=round(AllColumns);
sig = sig(AllColumns);

 My function can work correctly many times (for example 1000 times)
but suddenly it makes this error “Subscript Indices Must Be Real
Positive Integers or Logicals”
And running stops. I don’t know what happens, I have rounded my
indices, but I have this error yet.
I produce my indices in this way, but I don’t know why MATLAB
sometimes has this error, maybe it is for MATLAB arithmetic.
Help me please
I need to run my function many times.
Thanks for your attention.

Subject: Matrix indices

From: Pekka Kumpulainen

Date: 29 Jan, 2012 11:16:10

Message: 2 of 8

rahill <raheleh.baharloo@gmail.com> wrote in message <7935790b-4cbe-4387-b8c7-7f6266349bc3@rk3g2000pbb.googlegroups.com>...
> Hi every body
> I have one section in my function that produces matrix indices and
> then I reshape my matrix according to those Indices.
> OneColumnIndex=bsxfun(@plus,(1:ll).',11250.*(0:n_cut-1));
> ColumnsIncrements=reshape ((0:RChunk-1).*180000,1,1,[]);
> AllColumns=bsxfun(@plus,oneColumnIndex,ColumnIncrements);
> AllColumns=round(AllColumns);
> sig = sig(AllColumns);
>
> My function can work correctly many times (for example 1000 times)
> but suddenly it makes this error “Subscript Indices Must Be Real
> Positive Integers or Logicals”
> And running stops. I don’t know what happens, I have rounded my
> indices, but I have this error yet.
> I produce my indices in this way, but I don’t know why MATLAB
> sometimes has this error, maybe it is for MATLAB arithmetic.
> Help me please
> I need to run my function many times.
> Thanks for your attention.

Tell MATLAB debugger to stop at error and you can check what happens to your indices
>> dbstop if error
hth

Subject: Matrix indices

From: Roger Stafford

Date: 29 Jan, 2012 18:57:09

Message: 3 of 8

rahill <raheleh.baharloo@gmail.com> wrote in message <7935790b-4cbe-4387-b8c7-7f6266349bc3@rk3g2000pbb.googlegroups.com>...
> My function can work correctly many times (for example 1000 times)
> but suddenly it makes this error “Subscript Indices Must Be Real
> Positive Integers or Logicals”
> And running stops.
- - - - - - - - - -
  You haven't said how large "n_cut" and "RChunk" are. If the maximum value in 'AllColumns',

 11+11250*(n_cut-1)+(RChunk-1)*180000 ,

is excessively large and being used as an index, that could lead to all kinds of difficulties. As Pekka suggests, use your debug facility to study the situation when your error occurs.

  Note that matlab's addition, subtraction, and multiplication operations on integers are always exact unless the quantities involved exceed 2^53 which is about 9e15. (Your 'round' operation accomplishes nothing whatever - the results are already integers.) Beyond that limit, matlab's double floating point integers must be rounded to the nearest 53-bit representation. (For example, 2^53+1 will automatically be rounded down to 2^53, and 2^55+14 up to 2^55+16.) You should check that that never occurs in your calculations. Also I believe there is some kind of size limit imposed on array indices which you should be concerned about.

Roger Stafford

Subject: Matrix indices

From: rahill

Date: 30 Jan, 2012 19:39:59

Message: 4 of 8

On Jan 29, 10:57 am, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> rahill<raheleh.bahar...@gmail.com> wrote in message <7935790b-4cbe-4387-b8c7-7f6266349...@rk3g2000pbb.googlegroups.com>...
> >  My function can work correctly many times (for example 1000 times)
> > but suddenly it makes this error “Subscript Indices Must Be Real
> > Positive Integers or Logicals”
> > And running stops.
>
> - - - - - - - - - -
>   You haven't said how large "n_cut" and "RChunk" are.  If the maximum value in 'AllColumns',
>
>  11+11250*(n_cut-1)+(RChunk-1)*180000  ,
>
> is excessively large and being used as an index, that could lead to all kinds of difficulties.  As Pekka suggests, use your debug facility to study the situation when your error occurs.
>
>   Note that matlab's addition, subtraction, and multiplication operations on integers are always exact unless the quantities involved exceed 2^53 which is about 9e15.  (Your 'round' operation accomplishes nothing whatever  - the results are already integers.)  Beyond that limit, matlab's double floating point integers must be rounded to the nearest 53-bit representation.  (For example, 2^53+1 will automatically be rounded down to 2^53, and 2^55+14 up to 2^55+16.)  You should check that that never occurs in your calculations.  Also I believe there is some kind of size limit imposed on array indices which you should be concerned about.
>
> Roger Stafford

Dear Roger
thanks for your attention
"n_cut" is 13, "Rchunk" vary between 1 to 20, and "ll" is 45000.
maybe the problem happens because of the large amount of my indices
matrix,I have test my function many times and I have saved all my
workspace after errors happend.but I dont know how can I understand
what is the problem, sometimes after stopping Matlab according to the
error I can do "sig = sig(AllColumns);" without any problem,while
Matlab has stopped running in the start of this line!! I dont know how
can i check such a large matrix. please help me.
thanks
Rahill

Subject: Matrix indices

From: Roger Stafford

Date: 30 Jan, 2012 23:52:10

Message: 5 of 8

rahill <raheleh.baharloo@gmail.com> wrote in message <96cf8ecc-8c37-44c3-ad60-d5b958c10f24@3g2000pbd.googlegroups.com>...
> > rahill<raheleh.bahar...@gmail.com> wrote in message <7935790b-4cbe-4387-b8c7-7f6266349...@rk3g2000pbb.googlegroups.com>...
> > >  My function can work correctly many times (for example 1000 times)
> > > but suddenly it makes this error “Subscript Indices Must Be Real
> > > Positive Integers or Logicals”
> > > And running stops.
> > ..........
> "n_cut" is 13, "Rchunk" vary between 1 to 20, and "ll" is 45000.
> maybe the problem happens because of the large amount of my indices
> matrix,I have test my function many times and I have saved all my
> workspace after errors happend.but I dont know how can I understand
> what is the problem, sometimes after stopping Matlab according to the
> error I can do "sig = sig(AllColumns);" without any problem,while
> Matlab has stopped running in the start of this line!! I dont know how
> can i check such a large matrix. please help me.
- - - - - - - - -
  With the values you quote your 'AllColumns' indices array is of size up to a three dimensional 45000*13*20 = 11700000 elements and its values range from 1 to 3600000. Matlab's 'double' numbers are fully capable of handling integers of this magnitude without error, but in the form of indices I am not sure how well they would be dealt with. After the

 sig = sig(AllColumns);

step the 'sig' array would then have 11700000 elements, which is a very large array and somewhere in matlab's processing this might require linear index values that large to access all of them. However, I would think that if there were trouble of this kind, it would be consistent for given values of 'LL', 'Rchunk', and 'n_cut'. I can't see offhand how it could depend on the initial contents of 'sig'. If 'sig' were too small to begin with, you should receive a different error message.

  What is it that varies between your different runs as far as this part of your code is concerned? You spoke of getting error indications only once in many trials. Is there any consistent pattern in the circumstances that prevail when the error occurs? It is possible this problem should be reported to the support people of Mathworks but I think they would need to see an example that they could consistently reproduce. Once in a thousand times would probably not be greeted with enthusiasm.

  By the way, you should make sure that your error message actually refers to the above 'sig' step rather than another step, to make sure that it is caused by something related to 'AllColumns' or 'sig'. Have you by any chance defined a function with this same name: 'sig'? That could give you all sorts of trouble, perhaps this particular error message, and is something always to be avoided.

Roger Stafford

Subject: Matrix indices

From: rahill

Date: 31 Jan, 2012 11:53:56

Message: 6 of 8

Dear Roger
Thanks for your helpful advises.
While I am checking all the error conditions,I tried to run my program
on another computer. and this is 8 hours running without any error in
new computer. I have to check more and do more tests.maybe this
problem happens because of internal problems of my computer.

I have to say I dont have any function with the name:"sig". And I try
to find any pattern in error situation.
Thank you very much for every thing.
I will Report the conclusion to you.
With the best wishes
Rahill.

Subject: Matrix indices

From: rahill

Date: 1 Feb, 2012 06:25:07

Message: 7 of 8

Dear Roger
Thanks for your helpful advises.
While I am checking all the error conditions,I tried to run my program
on another computer. and this is 8 hours running without any error in
new computer. I have to check more and do more tests.maybe this
problem happens because of internal problems of my computer.

I have to say I don't have any function with the name:"sig". And I try
to find any pattern in error situation.
Thank you very much for every thing.
I will Report the conclusion to you.
With the best wishes
Rahill.

Subject: Matrix indices

From: rahill

Date: 1 Feb, 2012 06:57:45

Message: 8 of 8

Dear Pekka
Thanks for replying.
Rahill

Tags for this Thread

No tags are associated with 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