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
 

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