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:
create/prelocate a cell

Subject: create/prelocate a cell

From: Wendy

Date: 5 Feb, 2010 23:20:20

Message: 1 of 4

I want to create a nested cell with 3 levels, ie. A{}{}{}. I want to prelocate this cell, as I am going to use it as a counting tool using the code below:

 OUTPUT{1,path_i}{1,Ka_i}{1,class_i} = OUTPUT{1,path_i}{1,Ka_i}{1,class_i}+1;

I need to initialize the cell. I tried OUTPUT=zeros{1:5}{1:4}{1:10}, but it does not work. Does anyone know how to initialize a nested cell? Or is there any suggestion for counting to avoid the use of existing value in a cell element?

Thank you very much,
Wendy

Subject: create/prelocate a cell

From: ade77

Date: 6 Feb, 2010 00:51:05

Message: 2 of 4

"Wendy " <wlq121@gmail.com> wrote in message <hki93k$7s6$1@fred.mathworks.com>...
> I want to create a nested cell with 3 levels, ie. A{}{}{}. I want to prelocate this cell, as I am going to use it as a counting tool using the code below:
>
> OUTPUT{1,path_i}{1,Ka_i}{1,class_i} = OUTPUT{1,path_i}{1,Ka_i}{1,class_i}+1;
>
> I need to initialize the cell. I tried OUTPUT=zeros{1:5}{1:4}{1:10}, but it does not work. Does anyone know how to initialize a nested cell? Or is there any suggestion for counting to avoid the use of existing value in a cell element?
>
> Thank you very much,
> Wendy

doc cell

Subject: create/prelocate a cell

From: James Tursa

Date: 6 Feb, 2010 03:00:07

Message: 3 of 4

"Wendy " <wlq121@gmail.com> wrote in message <hki93k$7s6$1@fred.mathworks.com>...
> I want to create a nested cell with 3 levels, ie. A{}{}{}. I want to prelocate this cell, as I am going to use it as a counting tool using the code below:
>
> OUTPUT{1,path_i}{1,Ka_i}{1,class_i} = OUTPUT{1,path_i}{1,Ka_i}{1,class_i}+1;
>
> I need to initialize the cell. I tried OUTPUT=zeros{1:5}{1:4}{1:10}, but it does not work. Does anyone know how to initialize a nested cell? Or is there any suggestion for counting to avoid the use of existing value in a cell element?
>
> Thank you very much,
> Wendy

Why are you trying to use a cell as opposed to a multi-dimensional array? e.g., why not

OUTPUT = zeros(5,4,10);
    :
OUTPUT(path_i,Ka_i,class_i) = OUTPUT(path_i,Ka_i,class_i)+1;

James Tursa

Subject: create/prelocate a cell

From: Jan Simon

Date: 6 Feb, 2010 17:13:03

Message: 4 of 4

Dear Wendy!

> I want to create a nested cell with 3 levels, ie. A{}{}{}. I want to prelocate this cell, as I am going to use it as a counting tool using the code below:
>
> OUTPUT{1,path_i}{1,Ka_i}{1,class_i} = OUTPUT{1,path_i}{1,Ka_i}{1,class_i}+1;

> OUTPUT=zeros{1:5}{1:4}{1:10}
> but it does not work

This is not surprising, because it is obviously no valid Matlab syntax. Please look at: help zeros

You cannot pre-allocate nested cells in a single step. You have to do this for each level individually:
  C3 = cell(1, class_n);
  C3(:) = {1}; % fill in your wanted data here!
  C2 = cell(1, Ka_n);
  C2(:) = {C3};
  C1 = cell(1, path_n);
  C1(:) = {C2};

Nevertheless, I assume that there is a better method to organize your data that 3 nested cells.

Kind regards, Jan

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