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:
??? Attempted to access x(3); index out of bounds because numel(x)=1.

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Priyank Thakor

Date: 26 Oct, 2010 14:18:03

Message: 1 of 9

Hi,

I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion and I am getting the following error

??? Attempted to access x(3); index out of bounds
because numel(x)=1.

My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)

and my function is as follows,

function dx = abc(t,x)
t=0;
x=0;
dx=zeros(6,1);
dx(1)= 0.1*x(1)^2+(sin(t))^2*x(3)^2-10; Error in ==> abc at 5.

Appreciate your help guys

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Sean

Date: 26 Oct, 2010 14:25:07

Message: 2 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6nur$h97$1@fred.mathworks.com>...
> Hi,
>
> I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion and I am getting the following error
>
> ??? Attempted to access x(3); index out of bounds
> because numel(x)=1.
>
> My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)
>
> and my function is as follows,
>
> function dx = abc(t,x)
> t=0;
> x=0;
> dx=zeros(6,1);
> dx(1)= 0.1*x(1)^2+(sin(t))^2*x(3)^2-10; Error in ==> abc at 5.
>
> Appreciate your help guys

x = 0; %a scalar value

x(3) does not exist. Just like the error message says.

Do you mean to overwrite your input x on line 3? I'll bet MLINT (the orange lines on the side) has one on the first line that says "x appears to be unused"

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Matt J

Date: 26 Oct, 2010 14:27:05

Message: 3 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6nur$h97$1@fred.mathworks.com>...
> Hi,
>
> I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion and I am getting the following error
>
> ??? Attempted to access x(3); index out of bounds
> because numel(x)=1.
>
> My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)
>
> and my function is as follows,
>
> function dx = abc(t,x)
> t=0;
> x=0;

You probably want to remove the first two lines of your function. They are overwriting your input arguments. In particular, x=0 makes it so that length(x)=1 and so that
x(3) is unavailable for these next few lines:




> dx=zeros(6,1);
> dx(1)= 0.1*x(1)^2+(sin(t))^2*x(3)^2-10; Error in ==> abc at 5.
>
> Appreciate your help guys

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Priyank Thakor

Date: 26 Oct, 2010 14:35:03

Message: 4 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6nur$h97$1@fred.mathworks.com>...
> Hi,
>
> I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion and I am getting the following error
>
> ??? Attempted to access x(3); index out of bounds
> because numel(x)=1.
>
> My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)
>
> and my function is as follows,
>
> function dx = abc(t,x)
> t=0;
> x=0;
> dx=zeros(6,1);
> dx(1)= 0.1*x(1)^2+(sin(t))^2*x(3)^2-10; Error in ==> abc at 5.
>
> Appreciate your help guys

@ Sean : No I do not want to overwrite the input. I just want the solution.

@ Matt : If I delete my first two lines, it says X is undefined

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Matt J

Date: 26 Oct, 2010 14:55:30

Message: 5 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6oun$pnh$1@fred.mathworks.com>...
>
> @ Matt : If I delete my first two lines, it says X is undefined

That would be a problem unrelated to any code you've shown us. The code you've shown us involves a variable called 'x' (lower case) and not 'X' (upper case).

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Priyank Thakor

Date: 26 Oct, 2010 15:04:05

Message: 6 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6nur$h97$1@fred.mathworks.com>...
> Hi,
>
> I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion and I am getting the following error
>
> ??? Attempted to access x(3); index out of bounds
> because numel(x)=1.
>
> My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)
>
> and my function is as follows,
>
> function dx = abc(t,x)
> t=0;
> x=0;
> dx=zeros(6,1);
> dx(1)= 0.1*x(1)^2+(sin(t))^2*x(3)^2-10; Error in ==> abc at 5.
>
> Appreciate your help guys

@ Matt - Sorry for the Typo mistake .. It is "x"

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Matt J

Date: 26 Oct, 2010 15:22:04

Message: 7 of 9

"Priyank Thakor" <priyank3370@gmail.com> wrote in message <ia6ql5$luq$1@fred.mathworks.com>...
>
> @ Matt - Sorry for the Typo mistake .. It is "x"
==============

Then possibly you have a typo in the function call. In any case, I can't reproduce the problem. When I run abs(0,zeros(1,3)) with the first 2 lines deleted, I get no problems.

In any case also, surely you must agree that those first two lines make no sense. What was your intention in deleting/overwriting your input arguments to abc() as the very first step in the function. What would be useful about that?

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Steven_Lord

Date: 26 Oct, 2010 15:31:11

Message: 8 of 9



"Priyank Thakor" <priyank3370@gmail.com> wrote in message
news:ia6nur$h97$1@fred.mathworks.com...
> Hi,
>
> I am trying to calculated solution of 6 ODE's using Matlabs ODE45 fucntion
> and I am getting the following error
>
> ??? Attempted to access x(3); index out of bounds
> because numel(x)=1.
>
> My call ODE call function is [t,x]=ode23(abc,[0 2*pi],ival)

As written, this code attempts to call your abc function with 0 inputs and
use the output argument as the ODE function of your call to ODE23. Since
you want to use your abc function directly as the ODE function, you need to
pass a function handle to abc into ODE23.

[t, x] = ode23(@abc, [0 2*pi], ival);

> and my function is as follows,
>
> function dx = abc(t,x)
> t=0;
> x=0;

As others have said, get rid of the previous two lines that overwrite the
inputs with which ODE23 calls your function.

*snip*

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: ??? Attempted to access x(3); index out of bounds because numel(x)=1.

From: Matt J

Date: 26 Oct, 2010 15:33:04

Message: 9 of 9

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ia6rms$568$1@fred.mathworks.com>...
>
> Then possibly you have a typo in the function call. In any case, I can't reproduce the problem. When I run abs(0,zeros(1,3)) with the first 2 lines deleted, I get no problems.
=====

That should read abc(0,zeros(1,3))

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