Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: length of array

Subject: length of array

From: P Sherry

Date: 30 Jul, 2007 17:18:44

Message: 1 of 7

have an array:

P{a,b}

how do i find the length of P{2,b} i.e. where a is fixed and for all values of b

have tried:
sum(cellfun(@length,P)) but this does not allow for {a,b} individually

thanks
P

Subject: Re: length of array

From: us

Date: 30 Jul, 2007 17:26:41

Message: 2 of 7

P Sherry:
<SNIP cell acrobatics...

> P{a,b}
> how do i find the length of P{2,b}...

one of the solutions

     c={
          1:2 1:3
          1:4 1:5
          1:6 1:7
     };
     n=cellfun(@length,c(:,2))

us

Subject: Re: length of array

From: Matt

Date: 30 Jul, 2007 19:29:56

Message: 3 of 7

"P Sherry" <pistolpetesherry@nospam.hotmail.com> wrote in message <f8l6hk$epd$1@fred.mathworks.com>...
> have an array:
>
> P{a,b}
>
> how do i find the length of P{2,b} i.e. where a is fixed and for all values of b
>
> have tried:
> sum(cellfun(@length,P)) but this does not allow for {a,b} individually
>
> thanks
> P


Try x=numel(P{2,b}).

Subject: Re: length of array

From: P Sherry

Date: 30 Jul, 2007 21:32:28

Message: 4 of 7

> n=cellfun(@length,c(:,2))
> Try x=numel(P{2,b}).

both work but think n=cellfun(@length,c(:,2)) works best for what im doing

NEW PROBLEM:

i have a loop for l and want to use it to find a value not already used in the array P{a}.

i had the following which partly works... som of the time but not all of the time???

for l = 1:N
    if ~any(P{2} == l-1)

is there another form of this? there is also an inner loop i.e. P{2,b} so l-1 cannot = any of {2,:}

Subject: Re: length of array

From: P Sherry

Date: 30 Jul, 2007 21:36:59

Message: 5 of 7

ps thanks for the prior replies.

any help with the ^^^^^^ would be much appreciated

P

Subject: Re: length of array

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 Jul, 2007 22:13:39

Message: 6 of 7

In article <f8lldc$h41$1@fred.mathworks.com>,
P Sherry <pistolpetesherry@nospam.hotmail.com> wrote:

>NEW PROBLEM:

>i have a loop for l and want to use it to find a value not already used in the array P{a}.

>i had the following which partly works... som of the time but not all of the time???

>for l = 1:N
> if ~any(P{2} == l-1)

>is there another form of this?


find( ~ismember( 0:N-1, P{2} ), 1 )

> there is also an inner loop i.e. P{2,b} so l-1 cannot = any of {2,:}

What is the size of P? Is it a 1 x something cell array, each
member of which is an array? Or is it a 2 x something cell array,
each member of which is an array? When you write P{2,b} do
you mean "the b'th column of the 2nd row of P", or do you mean
"the b'th element of the array P{2}" ? If P is really a 2 x something
cell array, P{2} is the same as P{2,1} .
--
Programming is what happens while you're busy making other plans.

Subject: Re: length of array

From: P Sherry

Date: 30 Jul, 2007 22:35:52

Message: 7 of 7


> find( ~ismember( 0:N-1, P{2} ), 1 )
>
> > there is also an inner loop i.e. P{2,b} so l-1 cannot = any of {2,:}
>
> What is the size of P? Is it a 1 x something cell array, each
> member of which is an array? Or is it a 2 x something cell array,
> each member of which is an array? When you write P{2,b} do
> you mean "the b'th column of the 2nd row of P", or do you mean
> "the b'th element of the array P{2}" ? If P is really a 2 x something
> cell array, P{2} is the same as P{2,1} .
> --
> Programming is what happens while you're busy making other plans.


the total size of P is N (e.g. 16) but can be split over a number of columns cells in any array i.e length of P{2} = N. its hard to explain but it based on permutations so each cell may be a different size.

for P{2,b} i mean the b'th column of the 2nd row of P

have to change the code around a bit to use :
find( ~ismember( 0:N-1, P{2} ), 1 )
so il keep you updated

thanks

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
code us 30 Jul, 2007 13:30:24
cell us 30 Jul, 2007 13:30:24
cellfun us 30 Jul, 2007 13:30:24
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics