http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373
MATLAB Central Newsreader  Matrix indices
Feed for thread: Matrix indices
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 29 Jan 2012 10:23:52 +0000
Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865121
rahill
Hi every body<br>
I have one section in my function that produces matrix indices and<br>
then I reshape my matrix according to those Indices.<br>
OneColumnIndex=bsxfun(@plus,(1:ll).',11250.*(0:n_cut1));<br>
ColumnsIncrements=reshape ((0:RChunk1).*180000,1,1,[]);<br>
AllColumns=bsxfun(@plus,oneColumnIndex,ColumnIncrements);<br>
AllColumns=round(AllColumns);<br>
sig = sig(AllColumns);<br>
<br>
My function can work correctly many times (for example 1000 times)<br>
but suddenly it makes this error “Subscript Indices Must Be Real<br>
Positive Integers or Logicals”<br>
And running stops. I don’t know what happens, I have rounded my<br>
indices, but I have this error yet.<br>
I produce my indices in this way, but I don’t know why MATLAB<br>
sometimes has this error, maybe it is for MATLAB arithmetic.<br>
Help me please<br>
I need to run my function many times.<br>
Thanks for your attention.

Sun, 29 Jan 2012 11:16:10 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865123
Pekka Kumpulainen
rahill <raheleh.baharloo@gmail.com> wrote in message <7935790b4cbe4387b8c77f6266349bc3@rk3g2000pbb.googlegroups.com>...<br>
> Hi every body<br>
> I have one section in my function that produces matrix indices and<br>
> then I reshape my matrix according to those Indices.<br>
> OneColumnIndex=bsxfun(@plus,(1:ll).',11250.*(0:n_cut1));<br>
> ColumnsIncrements=reshape ((0:RChunk1).*180000,1,1,[]);<br>
> AllColumns=bsxfun(@plus,oneColumnIndex,ColumnIncrements);<br>
> AllColumns=round(AllColumns);<br>
> sig = sig(AllColumns);<br>
> <br>
> My function can work correctly many times (for example 1000 times)<br>
> but suddenly it makes this error “Subscript Indices Must Be Real<br>
> Positive Integers or Logicals”<br>
> And running stops. I don’t know what happens, I have rounded my<br>
> indices, but I have this error yet.<br>
> I produce my indices in this way, but I don’t know why MATLAB<br>
> sometimes has this error, maybe it is for MATLAB arithmetic.<br>
> Help me please<br>
> I need to run my function many times.<br>
> Thanks for your attention.<br>
<br>
Tell MATLAB debugger to stop at error and you can check what happens to your indices<br>
>> dbstop if error<br>
hth

Sun, 29 Jan 2012 18:57:09 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865142
Roger Stafford
rahill <raheleh.baharloo@gmail.com> wrote in message <7935790b4cbe4387b8c77f6266349bc3@rk3g2000pbb.googlegroups.com>...<br>
> My function can work correctly many times (for example 1000 times)<br>
> but suddenly it makes this error “Subscript Indices Must Be Real<br>
> Positive Integers or Logicals”<br>
> And running stops.<br>
         <br>
You haven't said how large "n_cut" and "RChunk" are. If the maximum value in 'AllColumns',<br>
<br>
11+11250*(n_cut1)+(RChunk1)*180000 ,<br>
<br>
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.<br>
<br>
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 53bit 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.<br>
<br>
Roger Stafford

Mon, 30 Jan 2012 19:39:59 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865240
rahill
On Jan 29, 10:57 am, "Roger Stafford"<br>
<ellieandrogerxy...@mindspring.com.invalid> wrote:<br>
> rahill<raheleh.bahar...@gmail.com> wrote in message <7935790b4cbe4387b8c77f6266349...@rk3g2000pbb.googlegroups.com>...<br>
> > My function can work correctly many times (for example 1000 times)<br>
> > but suddenly it makes this error “Subscript Indices Must Be Real<br>
> > Positive Integers or Logicals”<br>
> > And running stops.<br>
><br>
>          <br>
> You haven't said how large "n_cut" and "RChunk" are. If the maximum value in 'AllColumns',<br>
><br>
> 11+11250*(n_cut1)+(RChunk1)*180000 ,<br>
><br>
> 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.<br>
><br>
> 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 53bit 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.<br>
><br>
> Roger Stafford<br>
<br>
Dear Roger<br>
thanks for your attention<br>
"n_cut" is 13, "Rchunk" vary between 1 to 20, and "ll" is 45000.<br>
maybe the problem happens because of the large amount of my indices<br>
matrix,I have test my function many times and I have saved all my<br>
workspace after errors happend.but I dont know how can I understand<br>
what is the problem, sometimes after stopping Matlab according to the<br>
error I can do "sig = sig(AllColumns);" without any problem,while<br>
Matlab has stopped running in the start of this line!! I dont know how<br>
can i check such a large matrix. please help me.<br>
thanks<br>
Rahill

Mon, 30 Jan 2012 23:52:10 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865265
Roger Stafford
rahill <raheleh.baharloo@gmail.com> wrote in message <96cf8ecc8c3744c3ad60d5b958c10f24@3g2000pbd.googlegroups.com>...<br>
> > rahill<raheleh.bahar...@gmail.com> wrote in message <7935790b4cbe4387b8c77f6266349...@rk3g2000pbb.googlegroups.com>...<br>
> > > My function can work correctly many times (for example 1000 times)<br>
> > > but suddenly it makes this error “Subscript Indices Must Be Real<br>
> > > Positive Integers or Logicals”<br>
> > > And running stops.<br>
> > ..........<br>
> "n_cut" is 13, "Rchunk" vary between 1 to 20, and "ll" is 45000.<br>
> maybe the problem happens because of the large amount of my indices<br>
> matrix,I have test my function many times and I have saved all my<br>
> workspace after errors happend.but I dont know how can I understand<br>
> what is the problem, sometimes after stopping Matlab according to the<br>
> error I can do "sig = sig(AllColumns);" without any problem,while<br>
> Matlab has stopped running in the start of this line!! I dont know how<br>
> can i check such a large matrix. please help me.<br>
        <br>
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<br>
<br>
sig = sig(AllColumns);<br>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Roger Stafford

Tue, 31 Jan 2012 11:53:56 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865299
rahill
Dear Roger<br>
Thanks for your helpful advises.<br>
While I am checking all the error conditions,I tried to run my program<br>
on another computer. and this is 8 hours running without any error in<br>
new computer. I have to check more and do more tests.maybe this<br>
problem happens because of internal problems of my computer.<br>
<br>
I have to say I dont have any function with the name:"sig". And I try<br>
to find any pattern in error situation.<br>
Thank you very much for every thing.<br>
I will Report the conclusion to you.<br>
With the best wishes<br>
Rahill.

Wed, 01 Feb 2012 06:25:07 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865398
rahill
Dear Roger<br>
Thanks for your helpful advises.<br>
While I am checking all the error conditions,I tried to run my program<br>
on another computer. and this is 8 hours running without any error in<br>
new computer. I have to check more and do more tests.maybe this<br>
problem happens because of internal problems of my computer.<br>
<br>
I have to say I don't have any function with the name:"sig". And I try<br>
to find any pattern in error situation.<br>
Thank you very much for every thing.<br>
I will Report the conclusion to you.<br>
With the best wishes<br>
Rahill.

Wed, 01 Feb 2012 06:57:45 +0000
Re: Matrix indices
http://www.mathworks.com/matlabcentral/newsreader/view_thread/316373#865399
rahill
Dear Pekka<br>
Thanks for replying.<br>
Rahill