Thread Subject: cell array size

Subject: cell array size

From: Hemin

Date: 11 Aug, 2008 02:44:02

Message: 1 of 7

I have cell array like that , for example multiple rows 6
rows with one column:
{[1,2]
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
[1,2,3,4,5,6]}

so how I can make an array that calculate size of each row.
for example the second row is 3, third row is 4 and 4th row
is 5 elements.
does any function that can make the length or the size of
each row of that cell array?

Subject: cell array size

From: Dina

Date: 11 Aug, 2008 02:53:02

Message: 2 of 7

"Hemin " <hemin.essa@ymail.com> wrote in message
<g7o91i$add$1@fred.mathworks.com>...
> I have cell array like that , for example multiple rows 6
> rows with one column:
> {[1,2]
> [1,2,3]
> [1,2,3,4]
> [1,2,3,4,5]
> [1,2,3,4,5,6]}
>
> so how I can make an array that calculate size of each
row.
> for example the second row is 3, third row is 4 and 4th
row
> is 5 elements.
> does any function that can make the length or the size of
> each row of that cell array?

u can use a for loop from 1:n and with every loop use the
size function .. size(x);

Subject: cell array size

From: Matt Fig

Date: 11 Aug, 2008 03:32:02

Message: 3 of 7

A = {[1,2]
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
[1,2,3,4,5,6]}

cellfun(@length,A)

Subject: cell array size

From: Hemin

Date: 11 Aug, 2008 03:32:03

Message: 4 of 7

"Dina " <corsair_dee@hotmail.com> wrote in message
<g7o9ie$dnh$1@fred.mathworks.com>...
> "Hemin " <hemin.essa@ymail.com> wrote in message
> <g7o91i$add$1@fred.mathworks.com>...
> > I have cell array like that , for example multiple rows
6
> > rows with one column:
> > {[1,2]
> > [1,2,3]
> > [1,2,3,4]
> > [1,2,3,4,5]
> > [1,2,3,4,5,6]}
> >
> > so how I can make an array that calculate size of each
> row.
> > for example the second row is 3, third row is 4 and 4th
> row
> > is 5 elements.
> > does any function that can make the length or the size
of
> > each row of that cell array?
>
> u can use a for loop from 1:n and with every loop use the
> size function .. size(x);

i have tried with the function ,but it doesnt shows that to
me.
if u c my code

load_matrix=[]; % creating a load matrix which is
summention of paths on each flow
n=size(route_path);
for i=1:n
    
   El=route_path(i)
   m=size(El);
   
     for j=1:m-1
        load_matrix =[load_matrix traffic_m(El(j),El
(j+1))];
     end
    
end

Subject: cell array size

From: Matt Fig

Date: 11 Aug, 2008 03:40:04

Message: 5 of 7

A = {[1,2]
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
[1,2,3,4,5,6]}


You COULD do this in a loop:

lngth = zeros(length(A),1); % Preallocate
for kk = 1:length(A)
    lngth(kk) = length(A{kk});
end



Or you could just use:

cellfun(@length,A)

Subject: cell array size

From: Donn Shull

Date: 18 Aug, 2008 14:16:02

Message: 6 of 7

"Hemin " <hemin.essa@ymail.com> wrote in message
<g7o91i$add$1@fred.mathworks.com>...
> I have cell array like that , for example multiple rows 6
> rows with one column:
> {[1,2]
> [1,2,3]
> [1,2,3,4]
> [1,2,3,4,5]
> [1,2,3,4,5,6]}
>
> so how I can make an array that calculate size of each
row.
> for example the second row is 3, third row is 4 and 4th
row
> is 5 elements.
> does any function that can make the length or the size of
> each row of that cell array?

use cellfun:

a = {[1,2]
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
[1,2,3,4,5,6]};

b = cellfun('length', a);

Donn




Subject: cell array size

From: Donn Shull

Date: 18 Aug, 2008 21:42:01

Message: 7 of 7

"Hemin " <hemin.essa@ymail.com> wrote in message
<g7o91i$add$1@fred.mathworks.com>...
> I have cell array like that , for example multiple rows 6
> rows with one column:
> {[1,2]
> [1,2,3]
> [1,2,3,4]
> [1,2,3,4,5]
> [1,2,3,4,5,6]}
>
> so how I can make an array that calculate size of each
row.
> for example the second row is 3, third row is 4 and 4th
row
> is 5 elements.
> does any function that can make the length or the size of
> each row of that cell array?

use cellfun

>> a = {[1,2]
[1,2,3]
[1,2,3,4]
[1,2,3,4,5]
[1,2,3,4,5,6]}

a =

    [1x2 double]
    [1x3 double]
    [1x4 double]
    [1x5 double]
    [1x6 double]


>> b = cellfun('length', a)

b =

     2
     3
     4
     5
     6


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
cellfun Matt Fig 10 Aug, 2008 23:32:06
cell array Hemin 10 Aug, 2008 22:47:55
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com