Thread Subject: Subscript indices

Subject: Subscript indices

From: S?bastien Vilaseca

Date: 17 Feb, 2009 12:08:02

Message: 1 of 9

Hi,
I have the following loop:

for x=[0.001:0.001:0.1]
result(x)=y;
end

The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?

Thanks a lot.

Subject: Subscript indices

From: Bruno Luong

Date: 17 Feb, 2009 12:13:02

Message: 2 of 9

"S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> Hi,
> I have the following loop:
>
> for x=[0.001:0.001:0.1]
> result(x)=y;
> end
>
> The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?
>

No. As the error message tells, Matlab accepts integer indices only (>=1).

Bruno
 

Subject: Subscript indices

From: Jos

Date: 17 Feb, 2009 12:34:02

Message: 3 of 9

"S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> Hi,
> I have the following loop:
>
> for x=[0.001:0.001:0.1]
> result(x)=y;
> end
>
> The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?

What is "it" in ".. so I can make it ..."?

Jos

Subject: Subscript indices

From: S?bastien Vilaseca

Date: 17 Feb, 2009 12:59:02

Message: 4 of 9

"Jos " <#10584@fileexchange.com> wrote in message <gnearq$hnu$1@fred.mathworks.com>...
> "S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> > Hi,
> > I have the following loop:
> >
> > for x=[0.001:0.001:0.1]
> > result(x)=y;
> > end
> >
> > The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?
>
> What is "it" in ".. so I can make it ..."?
>
> Jos

So I can find the solution :).

Subject: Subscript indices

From: Jos

Date: 17 Feb, 2009 13:06:02

Message: 5 of 9

"S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gnecam$1jv$1@fred.mathworks.com>...
> "Jos " <#10584@fileexchange.com> wrote in message <gnearq$hnu$1@fred.mathworks.com>...
> > "S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> > > Hi,
> > > I have the following loop:
> > >
> > > for x=[0.001:0.001:0.1]
> > > result(x)=y;
> > > end
> > >
> > > The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?
> >
> > What is "it" in ".. so I can make it ..."?
> >
> > Jos
>
> So I can find the solution :).

Sure! But which solution?

What should your solution look like? In other words, what is "it"?

"The largest part of the answer is in asking the right question"

Jos

Subject: Subscript indices

From: John D'Errico

Date: 17 Feb, 2009 13:11:02

Message: 6 of 9

"S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gnecam$1jv$1@fred.mathworks.com>...
> "Jos " <#10584@fileexchange.com> wrote in message <gnearq$hnu$1@fred.mathworks.com>...
> > "S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> > > Hi,
> > > I have the following loop:
> > >
> > > for x=[0.001:0.001:0.1]
> > > result(x)=y;
> > > end
> > >
> > > The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?
> >
> > What is "it" in ".. so I can make it ..."?
> >
> > Jos
>
> So I can find the solution :).

You cannot do so. MATLAB does not allow you to
index a matrix with non-positive integer indices.
At least not unless you define your own objects,
then explicitly define how subsref and subsasgn
work.

You can do an assignment like this:

result(1) = stuff;

you cannot do this

result(0.001) = stuff;

Just wanting to do something will not make it so.
I believe the old phrase was "If wishes were horses,
beggars would ride."

John

Subject: Subscript indices

From: Andrew

Date: 17 Feb, 2009 14:23:52

Message: 7 of 9

On Feb 17, 6:06=A0am, "Jos " <#10...@fileexchange.com> wrote:
> "S?bastien Vilaseca" <seb2...@bluewin.ch> wrote in message <gnecam$1j...@=
fred.mathworks.com>...
> > "Jos " <#10...@fileexchange.com> wrote in message <gnearq$hn...@fred.ma=
thworks.com>...
> > > "S?bastien Vilaseca" <seb2...@bluewin.ch> wrote in message <gne9b2$46=
...@fred.mathworks.com>...
> > > > Hi,
> > > > I have the following loop:
>
> > > > for x=3D[0.001:0.001:0.1]
> > > > result(x)=3Dy;
> > > > end
>
> > > > The problem is that I get the following error message: "Subscript i=
ndices must either be real positive integers or logicals". So is there a wa=
y I can make it without that error?
>
> > > What is "it" in ".. so I can make it ..."?
>
> > > Jos
>
> > So I can find the solution :).
>
> Sure! But which solution?
>
> What should your solution look like? In other words, what is "it"?
>
> "The largest part of the answer is in asking the right question"
>
> Jos

"Indices" refers to the numbering system matlab uses to access each
element of an array. If you have an array: x=3D[1, 2, 1, 4, 6, 5, 7];
you can see that there are 7 elements in the array. So, x(1) is the
first element, and x(7) is the 7th element. If you asked for x(8),
you would get an error because the array doesn't have 8 elements. And
if you asked for x(0.1) you would get an error because there cannot be
a non integer index value used to reference one of the elements of the
array.

On the other hand, if you had the array x =3D [0.001:0.001:1] and you
asked for x(1), you would get the value at x(1) which is 0.001, and x
(2) would be 0.002...etc.

Subject: Subscript indices

From: us

Date: 17 Feb, 2009 14:37:02

Message: 8 of 9

"S?bastien Vilaseca"
> I have the following loop:
> for x=[0.001:0.001:0.1]
> result(x)=y;
> end
> The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error...

yes, peruse this great intro by steve eddins and loren shure

http://www.mathworks.com/company/newsletters/digest/sept01/matrix.html

us

Subject: Subscript indices

From: Bruno Luong

Date: 20 Feb, 2009 12:09:02

Message: 9 of 9

"S?bastien Vilaseca" <seb2000@bluewin.ch> wrote in message <gne9b2$46o$1@fred.mathworks.com>...
> Hi,
> I have the following loop:
>
> for x=[0.001:0.001:0.1]
> result(x)=y;
> end
>
> The problem is that I get the following error message: "Subscript indices must either be real positive integers or logicals". So is there a way I can make it without that error?
>
> Thanks a lot.

Actually you could do this:

x=[0.001:0.001:0.1];
result=containers.Map(inf,inf); % create with dummy
for x=[0.001:0.001:0.1]
    y=rand();
    result(x)=y;
end
remove(result,Inf); % remove the dummy

x=0.002
result(x) % beware of floating-point limited precision...

% Bruno

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
linear us 17 Feb, 2009 09:41:29
matrix us 17 Feb, 2009 09:41:29
vector us 17 Feb, 2009 09:41:29
logical us 17 Feb, 2009 09:41:29
indexing us 17 Feb, 2009 09:41:29
reference us 17 Feb, 2009 09:40:22
rssFeed for this Thread

Contact us at files@mathworks.com