Thread Subject: "Subscript indices must either be real positive integers or

Subject: "Subscript indices must either be real positive integers or

From: Muffin

Date: 12 Feb, 2008 21:27:30

Message: 1 of 14

I plotted data and then fitted it with a curve. Now I want to find a
point between the data points where the area under the curve equals
the area over the curve. This was working on another computer last
night with an older version of Matlab but now the error:

Subscript indices must either be real positive integers or logicals.

keeps coming up.

%1.a)

%This plots the x-axis vs. the y-axis data points. I transposed it
into a
%column vector
X = [0.1:0.1:1.6]'
Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
9683, .9817, .9897, .9943, .9969, .9983, 1.0]'

%Here, I fitted the data points using a cubicspline and plotted the
curve. Unfortunately, the fit
%option is on older versions of Matlab so it may not work on every
computer
%since I wrote the code in the Bard computer room where they were
older
%versions

Xdata = 0.1:.001:1.6;
plane = spline(X, Y, Xdata)

plot(X, Y, 'ko', Xdata, plane, 'r-')

%This labelled the plot
xLabel(' x (cm)')
yLabel('Normalized Concentration Ca/Co')

%This set to functions equal to y and the other to 1-y
f = @(X)plane(X)
g = @(X)1-plane(X)

%quad integrates the function and then matano finds the point where
the
%area under the curve is equal to the area above the curve

matano = @(X)quad(f, .5, X) -quad(g, X, 1.6);
fzero(matano, 0.1,1.6)

What should I do to fix this?

Subject: "Subscript indices must either be real positive integers or

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 21:36:49

Message: 2 of 14

In article <46b5fd6c-5318-4335-b6c6-87469613b630@s8g2000prg.googlegroups.com>,
Muffin <aam47@cornell.edu> wrote:
>I plotted data and then fitted it with a curve. Now I want to find a
>point between the data points where the area under the curve equals
>the area over the curve. This was working on another computer last
>night with an older version of Matlab but now the error:

>Subscript indices must either be real positive integers or logicals.
>keeps coming up.

>Xdata = 0.1:.001:1.6;
>plane = spline(X, Y, Xdata)

If you had a variable named 'spline', or if for some reason the
routine named 'spline' could not be found, then Matlab would think
you were trying to access a variable named 'spline' with
indices that were not integers.

spline() does appear to be a part of basic matlab, at least in
R2007a. I glanced around but could not find any information as
to when it was introduced as an independant function
(as an option to interp1 it goes back to at least Matlab 6.1)
--
  "When a scientist is ahead of his times, it is often through
   misunderstanding of current, rather than intuition of future truth.
   In science there is never any error so gross that it won't one day,
   from some perspective, appear prophetic." -- Jean Rostand

Subject: "Subscript indices must either be real positive integers or

From: Muffin

Date: 12 Feb, 2008 21:40:06

Message: 3 of 14

On Feb 12, 4:36 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In article <46b5fd6c-5318-4335-b6c6-87469613b...@s8g2000prg.googlegroups.com>,
>
> Muffin <aa...@cornell.edu> wrote:
> >I plotted data and then fitted it with a curve. Now I want to find a
> >point between the data points where the area under the curve equals
> >the area over the curve. This was working on another computer last
> >night with an older version of Matlab but now the error:
> >Subscript indices must either be real positive integers or logicals.
> >keeps coming up.
> >Xdata = 0.1:.001:1.6;
> >plane = spline(X, Y, Xdata)
>
> If you had a variable named 'spline', or if for some reason the
> routine named 'spline' could not be found, then Matlab would think
> you were trying to access a variable named 'spline' with
> indices that were not integers.
>
> spline() does appear to be a part of basic matlab, at least in
> R2007a. I glanced around but could not find any information as
> to when it was introduced as an independant function
> (as an option to interp1 it goes back to at least Matlab 6.1)
> --
> "When a scientist is ahead of his times, it is often through
> misunderstanding of current, rather than intuition of future truth.
> In science there is never any error so gross that it won't one day,
> from some perspective, appear prophetic." -- Jean Rostand

spline is a routine here. I used help spline. Do you have any other
ideas to fit the data points then so I can use the function fzero.
Apparently, that is where the error message: "Subscript indices must
either be real positive integers or logicals." are coming up

Subject: "Subscript indices must either be real positive integers or

From: Muffin

Date: 12 Feb, 2008 21:45:48

Message: 4 of 14

On Feb 12, 4:40 pm, Muffin <aa...@cornell.edu> wrote:
> On Feb 12, 4:36 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
> wrote:
>
>
>
> > In article <46b5fd6c-5318-4335-b6c6-87469613b...@s8g2000prg.googlegroups.com>,
>
> > Muffin <aa...@cornell.edu> wrote:
> > >I plotted data and then fitted it with a curve. Now I want to find a
> > >point between the data points where the area under the curve equals
> > >the area over the curve. This was working on another computer last
> > >night with an older version of Matlab but now the error:
> > >Subscript indices must either be real positive integers or logicals.
> > >keeps coming up.
> > >Xdata = 0.1:.001:1.6;
> > >plane = spline(X, Y, Xdata)
>
> > If you had a variable named 'spline', or if for some reason the
> > routine named 'spline' could not be found, then Matlab would think
> > you were trying to access a variable named 'spline' with
> > indices that were not integers.
>
> > spline() does appear to be a part of basic matlab, at least in
> > R2007a. I glanced around but could not find any information as
> > to when it was introduced as an independant function
> > (as an option to interp1 it goes back to at least Matlab 6.1)
> > --
> > "When a scientist is ahead of his times, it is often through
> > misunderstanding of current, rather than intuition of future truth.
> > In science there is never any error so gross that it won't one day,
> > from some perspective, appear prophetic." -- Jean Rostand
>
> spline is a routine here. I used help spline. Do you have any other
> ideas to fit the data points then so I can use the function fzero.
> Apparently, that is where the error message: "Subscript indices must
> either be real positive integers or logicals." are coming up

I used interp1 and the same error message came up

Subject: Re:

From: Ian Clarkson

Date: 12 Feb, 2008 21:50:03

Message: 5 of 14

Muffin <aam47@cornell.edu> wrote in message <68c7fd7b-439e-
4f0f-9f73-45d3e809cfd4@d4g2000prg.googlegroups.com>...
> On Feb 12, 4:36 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter
Roberson)
> wrote:
> > In article <46b5fd6c-5318-4335-b6c6-
87469613b...@s8g2000prg.googlegroups.com>,
> >
> > Muffin <aa...@cornell.edu> wrote:
> > >I plotted data and then fitted it with a curve. Now I
want to find a
> > >point between the data points where the area under
the curve equals
> > >the area over the curve. This was working on another
computer last
> > >night with an older version of Matlab but now the
error:
> > >Subscript indices must either be real positive
integers or logicals.
> > >keeps coming up.
> > >Xdata = 0.1:.001:1.6;
> > >plane = spline(X, Y, Xdata)
> >
> > If you had a variable named 'spline', or if for some
reason the
> > routine named 'spline' could not be found, then Matlab
would think
> > you were trying to access a variable named 'spline'
with
> > indices that were not integers.
> >
> > spline() does appear to be a part of basic matlab, at
least in
> > R2007a. I glanced around but could not find any
information as
> > to when it was introduced as an independant function
> > (as an option to interp1 it goes back to at least
Matlab 6.1)
> > --
> > "When a scientist is ahead of his times, it is often
through
> > misunderstanding of current, rather than intuition
of future truth.
> > In science there is never any error so gross that
it won't one day,
> > from some perspective, appear prophetic." -- Jean
Rostand
>
> spline is a routine here. I used help spline. Do you
have any other
> ideas to fit the data points then so I can use the
function fzero.
> Apparently, that is where the error message: "Subscript
indices must
> either be real positive integers or logicals." are
coming up

try putting a "clear spline" before you call the function,
just to make sure.

Subject: Re:

From: Muffin

Date: 12 Feb, 2008 21:57:11

Message: 6 of 14

On Feb 12, 4:50 pm, "Ian Clarkson" <ian.clark...@gesturetek.com>
wrote:
> Muffin <aa...@cornell.edu> wrote in message <68c7fd7b-439e-
>
> 4f0f-9f73-45d3e809c...@d4g2000prg.googlegroups.com>...> On Feb 12, 4:36 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter
> Roberson)
> > wrote:
> > > In article <46b5fd6c-5318-4335-b6c6-
>
> 87469613b...@s8g2000prg.googlegroups.com>,
>
> > > Muffin <aa...@cornell.edu> wrote:
> > > >I plotted data and then fitted it with a curve. Now I
> want to find a
> > > >point between the data points where the area under
> the curve equals
> > > >the area over the curve. This was working on another
> computer last
> > > >night with an older version of Matlab but now the
> error:
> > > >Subscript indices must either be real positive
>
> integers or logicals.
>
> > > >keeps coming up.
> > > >Xdata = 0.1:.001:1.6;
> > > >plane = spline(X, Y, Xdata)
>
> > > If you had a variable named 'spline', or if for some
> reason the
> > > routine named 'spline' could not be found, then Matlab
> would think
> > > you were trying to access a variable named 'spline'
> with
> > > indices that were not integers.
>
> > > spline() does appear to be a part of basic matlab, at
> least in
> > > R2007a. I glanced around but could not find any
> information as
> > > to when it was introduced as an independant function
> > > (as an option to interp1 it goes back to at least
> Matlab 6.1)
> > > --
> > > "When a scientist is ahead of his times, it is often
> through
> > > misunderstanding of current, rather than intuition
> of future truth.
> > > In science there is never any error so gross that
> it won't one day,
> > > from some perspective, appear prophetic." -- Jean
> Rostand
>
> > spline is a routine here. I used help spline. Do you
> have any other
> > ideas to fit the data points then so I can use the
> function fzero.
> > Apparently, that is where the error message: "Subscript
> indices must
> > either be real positive integers or logicals." are
>
> coming up
>
> try putting a "clear spline" before you call the function,
> just to make sure

Im pretty sure the spline isn't a problem:

%1.a)

%This plots the x-axis vs. the y-axis data points. I transposed it
into a
%column vector
X = [0.1:0.1:1.6]'
Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
9683, .9817, .9897, .9943, .9969, .9983, 1.0]'

%Here, I fitted the data points using a cubicspline and plotted the
curve. Unfortunately, the fit
%option is on older versions of Matlab so it may not work on every
computer
%since I wrote the code in the Bard computer room where they were
older
%versions
Xdata = [0.1:.001:1.6]';
plane = spline(X, Y, Xdata)

plot(X, Y, 'ko', Xdata, plane, 'r-')

%This labelled the plot
xLabel(' x (cm)')
yLabel('Normalized Concentration Ca/Co')
clear spline
%This set to functions equal to y and the other to 1-y
f = @(X)plane(X)
g = @(X)1-plane(X)

%quad integrates the function and then matano finds the point where
the
%area under the curve is equal to the area above the curve

matano = @(X)quad(f, 0.1, X) - quad(g, X, 1.6);
fzero(matano, 0.1,1.6)

Subject: "Subscript indices must either be real positive integers or

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 22:01:19

Message: 7 of 14

In article <46b5fd6c-5318-4335-b6c6-87469613b630@s8g2000prg.googlegroups.com>,
Muffin <aam47@cornell.edu> wrote:

>Subscript indices must either be real positive integers or logicals.

>X = [0.1:0.1:1.6]'
>Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
>9683, .9817, .9897, .9943, .9969, .9983, 1.0]'

>Xdata = 0.1:.001:1.6;
>plane = spline(X, Y, Xdata)

At this point, plane will be the result of spline with those
input values, so plane will be an array.

>%This set to functions equal to y and the other to 1-y
>f = @(X)plane(X)
>g = @(X)1-plane(X)

For those to be meaningful, in view of the fast that plane is
an array, the X values passed to f and g must be integer subscripts
between 1 and the length of plane.


>matano = @(X)quad(f, .5, X) -quad(g, X, 1.6);

So you want to run quad() over f, evaluating f between
.5 and X, and you want to run quad() over g, evaluating g
between X and 1.6. That's going to request f(t) for t from .5 to X
and g(t) for t from X to 1.6 -- which is certainly going to
evaluate f and g at non-integers, thus trying to access plane()
at non-integers, leading to the error message you see.

>fzero(matano, 0.1,1.6)

>What should I do to fix this?

I don't know. I cannot tell what you are trying to do.
--
  "Do not on any account attempt to write on both sides of
  the paper at once." -- Walter C. Sellar

Subject: "Subscript indices must either be real positive integers or logicals." What should I do

From: Loren Shure

Date: 12 Feb, 2008 22:13:14

Message: 8 of 14

In article <46b5fd6c-5318-4335-b6c6-87469613b630
@s8g2000prg.googlegroups.com>, aam47@cornell.edu says...
> I plotted data and then fitted it with a curve. Now I want to find a
> point between the data points where the area under the curve equals
> the area over the curve. This was working on another computer last
> night with an older version of Matlab but now the error:
>
> Subscript indices must either be real positive integers or logicals.
>
> keeps coming up.
>
> %1.a)
>
> %This plots the x-axis vs. the y-axis data points. I transposed it
> into a
> %column vector
> X = [0.1:0.1:1.6]'
> Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
> 9683, .9817, .9897, .9943, .9969, .9983, 1.0]'
>
> %Here, I fitted the data points using a cubicspline and plotted the
> curve. Unfortunately, the fit
> %option is on older versions of Matlab so it may not work on every
> computer
> %since I wrote the code in the Bard computer room where they were
> older
> %versions
>
> Xdata = 0.1:.001:1.6;
> plane = spline(X, Y, Xdata)
>
> plot(X, Y, 'ko', Xdata, plane, 'r-')
>
> %This labelled the plot
> xLabel(' x (cm)')
> yLabel('Normalized Concentration Ca/Co')
>
> %This set to functions equal to y and the other to 1-y
> f = @(X)plane(X)
> g = @(X)1-plane(X)
>
> %quad integrates the function and then matano finds the point where
> the
> %area under the curve is equal to the area above the curve
>
> matano = @(X)quad(f, .5, X) -quad(g, X, 1.6);
> fzero(matano, 0.1,1.6)
>
> What should I do to fix this?
>

Use the debugger with dbstop if warning to see where this is occurring.

--
Loren
http://blogs.mathworks.com/loren/

Subject: "Subscript indices must either be real positive integers or

From: Muffin

Date: 12 Feb, 2008 22:19:35

Message: 9 of 14

%1.a)

%This plots the x-axis vs. the y-axis data points. I transposed it
into a
%column vector
X = [0.1:0.1:1.6]'
Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
9683, .9817, .9897, .9943, .9969, .9983, 1.0]'

%Here, I fitted the data points using a cubicspline and plotted the
curve. Unfortunately, the fit
%option is on older versions of Matlab so it may not work on every
computer
%since I wrote the code in the Bard computer room where they were
older
%versions
Xdata = [0.1:.001:1.6]';
plane = spline(X, Y, Xdata)

plot(X, Y, 'ko', Xdata, plane, 'r-')

%This labelled the plot
xLabel(' x (cm)')
yLabel('Normalized Concentration Ca/Co')
clear spline
%This set to functions equal to y and the other to 1-y
f = @(X)plane(X)
g = @(X)1-plane(X)

%quad integrates the function and then matano finds the point where
the
%area under the curve is equal to the area above the curve

matano = @(X)quad(f, 0.1, X) - quad(g, X, 1.6);
fzero(matano, 0.1, 1.6)



***I am integrating wrt 2 functions, f & g, along the x-axis to find
where the two areas are equal. Thus, it starts at .1 at f and ends at
1.6 at g, moving closer to a point x where f-g will equal 0. This is
called boltzmann-matano analysis. That is why I took small intervals
of .001 above in the code. However, b/c of fzero, the error message
pops up: "Subscript indices must either be real positive integers or
logicals." I know where in the code the error is. Now do you
understand what I am trying to do?

Subject: "Subscript indices must either be real positive integers or

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 23:24:39

Message: 10 of 14

In article <941e9383-5c50-4e1f-ad38-e9113288cb55@s19g2000prg.googlegroups.com>,
Muffin <aam47@cornell.edu> wrote:

>%This plots the x-axis vs. the y-axis data points. I transposed it
>into a
>%column vector
>X = [0.1:0.1:1.6]'
>Y = [0.0, .1472, .34331, .5235, .6701, .7803, .8586, .9118, .9464, .
>9683, .9817, .9897, .9943, .9969, .9983, 1.0]'

>Xdata = [0.1:.001:1.6]';
>plane = spline(X, Y, Xdata)

>f = @(X)plane(X)
>g = @(X)1-plane(X)

>matano = @(X)quad(f, 0.1, X) - quad(g, X, 1.6);
>fzero(matano, 0.1, 1.6)

>***I am integrating wrt 2 functions, f & g, along the x-axis to find
>where the two areas are equal. Thus, it starts at .1 at f and ends at
>1.6 at g, moving closer to a point x where f-g will equal 0. This is
>called boltzmann-matano analysis. That is why I took small intervals
>of .001 above in the code. However, b/c of fzero, the error message
>pops up: "Subscript indices must either be real positive integers or
>logicals." I know where in the code the error is. Now do you
>understand what I am trying to do?

No, I don't understand where the spline comes into it, and I
don't understand how you intend to convert a search technique (fzero)
that requires a continuous function into a search technique
that works only over discrete values (plane consists of discrete values).

If you only need to search over discrete X, then do not use fzero
or quad: use something like

rez = arrayfun(@(v) trapz(plane(1:v)) - trapz(plane(v:end)), ...
  1:length(plane));
[junk, loc] = min(abs(rez));
minv = rez(loc);
minloc = Xdata(loc);

then the minimum absolute difference would be minv at X location minloc .
--
  "A scientist who cannot prove what he has accomplished,
  has accomplished nothing." -- Walter Reisch

Subject: Re:

From: Philip Schlup

Date: 30 Jul, 2008 02:58:01

Message: 11 of 14

I've also come across this error while using INTERP1. In my
case, using linear interpolation, it fails on line 138,
   yiMat(p,j) = yMat(k,j) + s.*(yMat(k+1,j) - yMat(k,j));

This line is clearly valid. It executes smoothly when the
debugger breaks at this error and I enter it on the command
line. There is clearly no conflicting function / variable
name issue, as might be the case with 'spline.' So I doubt
that this is your problem.

I am, however, immediately suspicious of using 'j' as a loop
counter, since it is also defined as j = 1.00 + 1.00i, and
some conflict of this nature would explain the error message.

My suggestion: use a different Matlab version. The above
error appeared in Matlab 2006b, but not 2007a running the
same code with identical data. (We're running Win32.)

Subject: Re:

From: Sachitha Obeysekara

Date: 30 Jul, 2008 16:01:04

Message: 12 of 14

Usually this error is due to an index value being zero. For eg:
X(0) would throw this error.....


Subject: Re:

From: Nirav

Date: 16 Sep, 2008 10:58:02

Message: 13 of 14

"Sachitha Obeysekara" <sachitha.obeysekara@nospam.nokia.com> wrote in message <g6q380$m4e$1@fred.mathworks.com>...
> Usually this error is due to an index value being zero. For eg:
> X(0) would throw this error.....
>
>

---- REPLY ----

We also get this error when the index value being " NaN " ...
Sure about this....

Subject: "Subscript indices must either be real positive integers or

From: Ariel Padilla

Date: 13 Oct, 2008 21:05:05

Message: 14 of 14

Hi, I have the same problem, but mi function works great in matlab but qhen call it by .NET I recived the message,
somebody help me.

function = MatrizFusion (pAltoProb,pAnchoProb,pZa,pMi,pNi,pMf,pNf,pA,pAnchoFil,pAltoFil)
    Fi=1;
    Fj=1;
    for ii=1:pAltoProb
        for jj=1:pAnchoProb
            if (Za(ii,jj)==Za(pMi,pNi)) %This line
                for m = pMi:pMf
                    for n = pNi:pNf
                        Za(m,n) = a(Fi,Fj);
                        if Fj==pAnchoFil
                            Fj=1;
                            break
                        end
                        Fj=Fj+1;
                    end
                    if Fi==pAltoFil
                        Fi=1;
                        break
                    end
                    Fi=Fi+1;
                end
            end
        end
    end
    
    aa = Za;
    % fin de for de suma filtro/fondo

Tags for this Thread

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com