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:
cell simplify and initilialize

Subject: cell simplify and initilialize

From: Mike

Date: 20 Oct, 2012 01:55:09

Message: 1 of 2

Hi

following code needs to be simplified
>> A=cell(2,3);
>> A{1}(:)=[5:8,14:15,19:20]
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.

Sure following it's ok, but clumsy.
A{1,1}=5:8
A{1,2}=14:15
A{1,3}=19:20

Furthermore, if I need only one element for A(2,:), i.e. A{2,1} and not necessary for A{2,2} and A{2,3}, how to do it?

Thanks.

Mike

As for A{2,1}=24:25, I

Subject: cell simplify and initilialize

From: Steven_Lord

Date: 22 Oct, 2012 14:30:04

Message: 2 of 2



"Mike" <SulfateIon@gmail.com> wrote in message
news:924ee004-058c-45b0-ada0-8003c942ca5a@googlegroups.com...
> Hi
>
> following code needs to be simplified
>>> A=cell(2,3);
>>> A{1}(:)=[5:8,14:15,19:20]

One easy way:

A = cell(2, 3);
A(1, :) = {5:8, 14:15, 19:20};

> ??? In an assignment A(:) = B, the number of elements in A and B
> must be the same.
>
> Sure following it's ok, but clumsy.
> A{1,1}=5:8
> A{1,2}=14:15
> A{1,3}=19:20
>
> Furthermore, if I need only one element for A(2,:), i.e. A{2,1} and not
> necessary for A{2,2} and A{2,3}, how to do it?

If you're asking how to create a cell array with one row containing three
columns and one row containing one column, you cannot do this. Arrays of
built-in types in MATLAB MUST be hyperrectangular. You could implement your
own class so that it "looks like" it's a jagged array.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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