Thread Subject: Ignoring an empty array

Subject: Ignoring an empty array

From: Phil

Date: 1 Apr, 2009 12:45:03

Message: 1 of 4

Hi there.

Here is my problem. I have 3 arrays, 2 full and one empty in the format below

[15x1 double] [0x1 double] [24x1 double]

1.) How can i ignore the empty array

2.) But still recognise the order it is in i.e. [15x1 double] = 1st place, [0x1 double] = 2nd place and [24x1 double] = 3rd place.

Can anyone help?

Thanks in advance,

Phil

Subject: Ignoring an empty array

From: aasim Azooz

Date: 1 Apr, 2009 13:28:01

Message: 2 of 4

"Phil " <harsh_classic@yahoo.co.uk> wrote in message <gqvnkf$5q8$1@fred.mathworks.com>...
> Hi there.
>
> Here is my problem. I have 3 arrays, 2 full and one empty in the format below
>
> [15x1 double] [0x1 double] [24x1 double]
>
> 1.) How can i ignore the empty array
>
> 2.) But still recognise the order it is in i.e. [15x1 double] = 1st place, [0x1 double] = 2nd place and [24x1 double] = 3rd place.
>
> Can anyone help?
>
> Thanks in advance,
>
> Phil

See help squeeze
Aasim Azooz

Subject: Ignoring an empty array

From: Jos

Date: 1 Apr, 2009 14:06:02

Message: 3 of 4

"Phil " <harsh_classic@yahoo.co.uk> wrote in message <gqvnkf$5q8$1@fred.mathworks.com>...
> Hi there.
>
> Here is my problem. I have 3 arrays, 2 full and one empty in the format below
>
> [15x1 double] [0x1 double] [24x1 double]
>
> 1.) How can i ignore the empty array
>
> 2.) But still recognise the order it is in i.e. [15x1 double] = 1st place, [0x1 double] = 2nd place and [24x1 double] = 3rd place.
>
> Can anyone help?
>
> Thanks in advance,
>
> Phil

Are these arrays stored in a cell array? A lazy suggestion could be:

% data
C = {[1 2 3],[],[6 7 8 9 10]}

% create a place vector
place = C ;
for i=1:numel(C),
 t = place{i} ;
 t(:) = i ;
 place{i} = t ;
end
Result = [place{:} ; C{:}]

More matlab-like alternatives could include cellfun, cell2struct etc. But it depends on what you need to do exactly, and what you mean by "ignore the empty array"?

hth
Jos

Subject: Ignoring an empty array

From: Phil

Date: 1 Apr, 2009 14:26:01

Message: 4 of 4

"Jos " <#10584@fileexchange.com> wrote in message <gqvsc9$9kk$1@fred.mathworks.com>...
> "Phil " <harsh_classic@yahoo.co.uk> wrote in message <gqvnkf$5q8$1@fred.mathworks.com>...
> > Hi there.
> >
> > Here is my problem. I have 3 arrays, 2 full and one empty in the format below
> >
> > [15x1 double] [0x1 double] [24x1 double]
> >
> > 1.) How can i ignore the empty array
> >
> > 2.) But still recognise the order it is in i.e. [15x1 double] = 1st place, [0x1 double] = 2nd place and [24x1 double] = 3rd place.
> >
> > Can anyone help?
> >
> > Thanks in advance,
> >
> > Phil
>
> Are these arrays stored in a cell array? A lazy suggestion could be:
>
> % data
> C = {[1 2 3],[],[6 7 8 9 10]}
>
> % create a place vector
> place = C ;
> for i=1:numel(C),
> t = place{i} ;
> t(:) = i ;
> place{i} = t ;
> end
> Result = [place{:} ; C{:}]
>
> More matlab-like alternatives could include cellfun, cell2struct etc. But it depends on what you need to do exactly, and what you mean by "ignore the empty array"?
>
> hth
> Jos

Hi Jos,

Many thanks for your help. I have managed to sort it now.

Kind regards,

Phil

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com