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:
multidimensional arrays

Subject: multidimensional arrays

From: Marc

Date: 21 Dec, 2009 02:12:04

Message: 1 of 8

Hello,

I can't get a multidimensional cell array with 3 dimensions (4 rows, 3 columns, 2 pages) to display after input data into the command window using the cat function. If someone could please help me figure out what I am doing wrong

thanks

This is what I entered into the command window:

DU>> A(1,1,) = 0.8
A{2,1,1} = 0.9
A{3,1,1} = 0.
A{1,2,1} = 7;
A{2,2,1} = 8
A{3,2,1} = 3;
A{4,2,1} = 3;
A{1,3,1} = 55(T) 45(F)
A (2,3,1) = 365(T) 325 (F)
A (3,3,1) = 2(PD) 5 (C)
A (4,3,1)= - 0.8 (PD) -0.6(C)
DU>> B(1,1,1) = 0.7
B{2,1,1} = 0.8
B{3,1,1} = 0.6
B{1,2,1} = 8;
B{2,2,1} = 9
B{3,2,1} = 4;
B{4,2,1} = 4;
B{1,3,1} = 65(T) 35(F)
B (2,3,1) = 355(T) 315 (F)
B(3,3,1) = 3(PD) 6(C)
B (4,3,1)= - 0.7 (PD) -0.5(C)
C = cat(4, A, B);

Subject: multidimensional arrays

From: Jan Simon

Date: 21 Dec, 2009 08:49:03

Message: 2 of 8

Dear Marc!

> I can't

Please specify this with more details. "Can't" does not contain someting helpful for us. What do you expect, what does happen? Please post the error message here.

> This is what I entered into the command window:
>
> DU>>
> A{2,1,1} = 0.9
> A{3,1,1} = 0.
> A{1,2,1} = 7;
> A{2,2,1} = 8
> A{3,2,1} = 3;
> A{4,2,1} = 3;
> A{1,3,1} = 55(T) 45(F)
> A (2,3,1) = 365(T) 325 (F)
> A (3,3,1) = 2(PD) 5 (C)
> A (4,3,1)= - 0.8 (PD) -0.6(C)
> DU>> B(1,1,1) = 0.7
> B{2,1,1} = 0.8
> B{3,1,1} = 0.6
> B{1,2,1} = 8;
> B{2,2,1} = 9
> B{3,2,1} = 4;
> B{4,2,1} = 4;
> B{1,3,1} = 65(T) 35(F)
> B (2,3,1) = 355(T) 315 (F)
> B(3,3,1) = 3(PD) 6(C)
> B (4,3,1)= - 0.7 (PD) -0.5(C)
> C = cat(4, A, B);

There must be error messages!
"A(1,1,) = 0.8" is not valid.
"A{1,3,1} = 55(T) 45(F)" should not work also.
Sometimes you write to A with curly braces {}, sometimes with round brackets (). Is this intented?

Kind regards, Jan

Subject: multidimensional arrays

From: Thomas Clark

Date: 21 Dec, 2009 11:17:04

Message: 3 of 8

marc,

What a way of filling in a matrix! It is a fluke that this hasn't generated an error.

I'd strongly suggest going through the help pages - there is a 'Getting started with MATLAB' section which you would benefit from.

The braces {} signify a 'cell' array, which is different to a normal array indicated by [] or ().

The cell array is an 'array of arrays' and contain data of different types - I'd suggest avoiding it until you have a better handle on how normal arrays work.

Also, you need to specify all elements of an array.

You cannot generate a multidimensional array by growing it one element at a time. You should initialise the array (with, say, the zeros function) beforehand.

Also, things like 55(T) 45(F) are invalid syntax. My guess is that you've come from some other language, or are expressing this like you might in a page of algebra. I think what you're trying to do is (55*T + 45*F) where T and F are scalar variables.

Again - go to the help tutorials first, and just invest some time learning how to use MATLAB before jumping in to writing your own code.

Tom

Subject: multidimensional arrays

From: Jan Simon

Date: 21 Dec, 2009 11:31:04

Message: 4 of 8

Dear Marc, dear Thomas

> You cannot generate a multidimensional array by growing it one element at a time. You should initialise the array (with, say, the zeros function) beforehand.

To be exact: You *can* create a multidim array by growing. But this is horribly slow. As Thomas writes correctly: You *should* not do this.

Kind regards, Jan

Subject: multidimensional arrays

From: Thomas Clark

Date: 21 Dec, 2009 13:27:03

Message: 5 of 8

Jan,

Apologies, you're right. I thought that something like:

A(1,1,1) = 1;
A(2,1,1) = 1;
A(1,2,1) = 1;

Would produce an error... but actually it grows the array, initialising zeros in the undefined elements. I may be thinking of a very old version of MATLAB, or some other language.

Anyhow, as we've said, growing the array is very computationally inefficient so it's a moot point!

Cheers

Tom


"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hgnm9o$94m$1@fred.mathworks.com>...
> Dear Marc, dear Thomas
>
> > You cannot generate a multidimensional array by growing it one element at a time. You should initialise the array (with, say, the zeros function) beforehand.
>
> To be exact: You *can* create a multidim array by growing. But this is horribly slow. As Thomas writes correctly: You *should* not do this.
>
> Kind regards, Jan

Subject: multidimensional arrays

From: Marc

Date: 24 Dec, 2009 07:08:02

Message: 6 of 8

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hgncpv$dv$1@fred.mathworks.com>...
> Dear Marc!
>
> > I can't
>
> Please specify this with more details. "Can't" does not contain someting helpful for us. What do you expect, what does happen? Please post the error message here.
>


> > This is what I entered into the command window:
> >
> > DU>>
> > A{2,1,1} = 0.9
> > A{3,1,1} = 0.
> > A{1,2,1} = 7;
> > A{2,2,1} = 8
> > A{3,2,1} = 3;
> > A{4,2,1} = 3;
> > A{1,3,1} = 55(T) 45(F)
> > A (2,3,1) = 365(T) 325 (F)
> > A (3,3,1) = 2(PD) 5 (C)
> > A (4,3,1)= - 0.8 (PD) -0.6(C)
> > DU>> B(1,1,1) = 0.7
> > B{2,1,1} = 0.8
> > B{3,1,1} = 0.6
> > B{1,2,1} = 8;
> > B{2,2,1} = 9
> > B{3,2,1} = 4;
> > B{4,2,1} = 4;
> > B{1,3,1} = 65(T) 35(F)
> > B (2,3,1) = 355(T) 315 (F)
> > B(3,3,1) = 3(PD) 6(C)
> > B (4,3,1)= - 0.7 (PD) -0.5(C)
> > C = cat(4, A, B);
>
> There must be error messages!
> "A(1,1,) = 0.8" is not valid.
> "A{1,3,1} = 55(T) 45(F)" should not work also.
> Sometimes you write to A with curly braces {}, sometimes with round brackets (). Is this intented?
>
> Kind regards, Jan


This is the error message I get:

??? DU>> A(1,1,) = 0.8
        |
Error: Unexpected MATLAB operator.

For the type of data and experiment I have run, I need to do a multidim cell array as in the example on the webpage:

http://www.mathworks.com/access/helpdesk/help/techdoc/math/f1-86528.html#f1-87418

thanks for the advice about the tutorials

Subject: multidimensional arrays

From: Jan Simon

Date: 24 Dec, 2009 09:40:06

Message: 7 of 8

Dear Marc!

> This is the error message I get:
> ??? DU>> A(1,1,) = 0.8
> |
> Error: Unexpected MATLAB operator.

So let's start from here.
The message means, that the line has no proper syntax. You have to insert a 3rd index for A.
Then, as written already, you have to decide if A is a DOUBLE array (with round brackets) or a cell array (with curly braces).

Have fun to proceed from here, Jan

Subject: multidimensional arrays

From: Steven Lord

Date: 1 Jan, 2010 03:55:31

Message: 8 of 8


"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message
news:hgvctm$cl4$1@fred.mathworks.com...
> Dear Marc!
>
>> This is the error message I get:
>> ??? DU>> A(1,1,) = 0.8
>> |
>> Error: Unexpected MATLAB operator.
>
> So let's start from here.
> The message means, that the line has no proper syntax. You have to insert
> a 3rd index for A.
> Then, as written already, you have to decide if A is a DOUBLE array (with
> round brackets) or a cell array (with curly braces).
>
> Have fun to proceed from here, Jan

The problem comes even before then. Marc, you're trying to copy the input
from a Command Window (or another instance's Command Window) and the input
you're trying to copy was entered into the Command Window of an instance of
the Student Version, but you copied part of the prompt as part of the input.
So, if you copy:

A(1,1,) = 0.8

then it should work (until you reach the issue highlighted by Jan -- give it
a third index.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

No tags are associated with 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