Thread Subject: Help with matlab arrays

Subject: Help with matlab arrays

From: Cesar B

Date: 23 Nov, 2009 21:38:18

Message: 1 of 4

Hi there! I need some help from more experienced users since I am kind of lost on what is going on in my code.

(1) I define an array line this:
BT(1,1)=0.125;
BT(1,2)=0.125;
BT(1,3)=0.125;
BT(1,4)=0.125;
BT(1,5)=0.125;
BT(1,6)=0.125;
BT(1,7)=0.125;
BT(2,1)=0.125;
BT(2,2)=0.125;
BT(2,3)=0.125;
BT(2,4)=0.125;
BT(2,5)=0.125;
BT(2,6)=0.125;
BT(2,7)=0.125;
BT(3,1)=0.125;
BT(3,2)=0.125;
BT(3,3)=0.125;
BT(3,4)=0.125;
BT(3,5)=0.125;
BT(3,6)=0.125;
BT(3,7)=0.125;
BT(4,1)=0.125;
BT(4,2)=0.125;
BT(4,3)=0.125;
BT(4,4)=0.125;
BT(4,5)=0.125;
BT(4,6)=0.125;
BT(4,7)=0.125;
BT(5,1)=0.125;
BT(5,2)=0.125;
BT(5,3)=0.125;
BT(5,4)=0.125;
BT(5,5)=0.125;
BT(5,6)=0.125;
BT(5,7)=0.125;
BT(6,1)=0.125;
BT(6,2)=0.125;
BT(6,3)=0.125;
BT(6,4)=0.125;
BT(6,5)=0.125;
BT(6,6)=0.125;
BT(6,7)=0.125;
BT(7,1)=0.125;
BT(7,2)=0.125;
BT(7,3)=0.125;
BT(7,4)=0.125;
BT(7,5)=0.125;
BT(7,6)=0.125;
BT(7,7)=0.125;

(2) I then call a function passing BT as part of it:
[X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);

(3) and in the function I receive it like this:
function [X0,P0,cb0,U0]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, P, BT, U1, U, cb)

(4) It errors like such when trying to multiply the arrays:
293 [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
??? Undefined function or method 'mtimes' for input arguments of type 'cell'.
Error in ==> imm_part1 at 18
      cb0(c,1)=cb0(c,1)+BT(r,c)*U1(r,1);
Error in ==> sf_main at 293
       [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);

Now, the problem is this. Investigating my problem I noticed (in debug mode) that up to the point I call the function the BT array is still a 7x7 "double" array like defined, but as soon as I step into the imm_part1 function then the BT array changes to a 1x7 cell, with each element now being a 2x2 "double" array (very different from how I defined it).

I could have swear I had this working before, but I guess it must be something on how I am passing the BT array? Any help will be greatly appreciated! :-)

Cesar

Subject: Help with matlab arrays

From: Nathan

Date: 23 Nov, 2009 21:44:27

Message: 2 of 4

On Nov 23, 1:38 pm, "Cesar B" <coyoteinven...@hotmail.com> wrote:
> Hi there! I need some help from more experienced users since I am kind of lost on what is going on in my code.
>
> (1) I define an array line this:
> BT(1,1)=0.125;
> BT(1,2)=0.125;
> BT(1,3)=0.125;
> BT(1,4)=0.125;
> BT(1,5)=0.125;
> BT(1,6)=0.125;
> BT(1,7)=0.125;
> BT(2,1)=0.125;
> BT(2,2)=0.125;
> BT(2,3)=0.125;
> BT(2,4)=0.125;
> BT(2,5)=0.125;
> BT(2,6)=0.125;
> BT(2,7)=0.125;
> BT(3,1)=0.125;
> BT(3,2)=0.125;
> BT(3,3)=0.125;
> BT(3,4)=0.125;
> BT(3,5)=0.125;
> BT(3,6)=0.125;
> BT(3,7)=0.125;
> BT(4,1)=0.125;
> BT(4,2)=0.125;
> BT(4,3)=0.125;
> BT(4,4)=0.125;
> BT(4,5)=0.125;
> BT(4,6)=0.125;
> BT(4,7)=0.125;
> BT(5,1)=0.125;
> BT(5,2)=0.125;
> BT(5,3)=0.125;
> BT(5,4)=0.125;
> BT(5,5)=0.125;
> BT(5,6)=0.125;
> BT(5,7)=0.125;
> BT(6,1)=0.125;
> BT(6,2)=0.125;
> BT(6,3)=0.125;
> BT(6,4)=0.125;
> BT(6,5)=0.125;
> BT(6,6)=0.125;
> BT(6,7)=0.125;
> BT(7,1)=0.125;
> BT(7,2)=0.125;
> BT(7,3)=0.125;
> BT(7,4)=0.125;
> BT(7,5)=0.125;
> BT(7,6)=0.125;
> BT(7,7)=0.125;
>
> (2) I then call a function passing BT as part of it:
> [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
>
> (3) and in the function I receive it like this:
> function [X0,P0,cb0,U0]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, P, BT, U1, U, cb)
>
> (4) It errors like such when trying to multiply the arrays:
> 293            [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
> ??? Undefined function or method 'mtimes' for input arguments of type 'cell'.
> Error in ==> imm_part1 at 18
>       cb0(c,1)=cb0(c,1)+BT(r,c)*U1(r,1);
> Error in ==> sf_main at 293
>        [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
>
> Now, the problem is this. Investigating my problem I noticed (in debug mode) that up to the point I call the function the BT array is still a 7x7 "double" array like defined, but as soon as I step into the imm_part1 function then the BT array changes to a 1x7 cell, with each element now being a 2x2 "double" array (very different from how I defined it).
>
> I could have swear I had this working before, but I guess it must be something on how I am passing the BT array? Any help will be greatly appreciated!  :-)
>
> Cesar

Quick note:
A quicker way to define your BT:
BT = ones(7).*.125

-Nathan

Subject: Help with matlab arrays

From: someone

Date: 23 Nov, 2009 21:51:18

Message: 3 of 4

"Cesar B" <coyoteinventor@hotmail.com> wrote in message <heevca$3p1$1@fred.mathworks.com>...
> Hi there! I need some help from more experienced users since I am kind of lost on what is going on in my code.
>
> (1) I define an array line this:
> BT(1,1)=0.125;
... snip ...
> BT(7,7)=0.125;
>
> (2) I then call a function passing BT as part of it:
> [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
>
> (3) and in the function I receive it like this:
> function [X0,P0,cb0,U0]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, P, BT, U1, U, cb)

Did you mean to reverse P & BT here?
You call it as: X, BT, P, U1,
but receive it as: X, P, BT, U1,

>
> (4) It errors like such when trying to multiply the arrays:
> 293 [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
> ??? Undefined function or method 'mtimes' for input arguments of type 'cell'.
> Error in ==> imm_part1 at 18
> cb0(c,1)=cb0(c,1)+BT(r,c)*U1(r,1);
> Error in ==> sf_main at 293
> [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
>
> Now, the problem is this. Investigating my problem I noticed (in debug mode) that up to the point I call the function the BT array is still a 7x7 "double" array like defined, but as soon as I step into the imm_part1 function then the BT array changes to a 1x7 cell, with each element now being a 2x2 "double" array (very different from how I defined it).
>
> I could have swear I had this working before, but I guess it must be something on how I am passing the BT array? Any help will be greatly appreciated! :-)
>
> Cesar

Subject: Help with matlab arrays

From: Cesar B

Date: 23 Nov, 2009 22:20:18

Message: 4 of 4

"someone" <someone@somewhere.net> wrote in message <hef04m$lel$1@fred.mathworks.com>...
> > (2) I then call a function passing BT as part of it:
> > [X,P,cb,U]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, BT, P, U1, U, cb);
> >
> > (3) and in the function I receive it like this:
> > function [X0,P0,cb0,U0]=imm_part1(ekf_status, sensors, s1_ekfs, s2_ekfs, s3_ekfs, X, P, BT, U1, U, cb)
>
> Did you mean to reverse P & BT here?
> You call it as: X, BT, P, U1,
> but receive it as: X, P, BT, U1,
>

Awesome! Thanks for pointing out the obvious! Now it makes sense! P is exactly was I was seeing for BT inside the function! I've flipped them and now I'm onto debugging other problems! Thanks again for your help!!! :-)))))

Cesar

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
arrays Cesar B 23 Nov, 2009 16:39:23
rssFeed for this Thread

Contact us at files@mathworks.com