Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news2!nx02.iad.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe02.iad.POSTED!7564ea0f!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Concatenate structure fields with empties
References: <gjo71f$ct5$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-C54CAA.13113803012009@news.frontiernet.net>
Lines: 37
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Sat, 03 Jan 2009 18:11:35 UTC
Organization: Frontier
Date: Sat, 03 Jan 2009 13:11:38 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:509676


In article <gjo71f$ct5$1@fred.mathworks.com>,
 "Sven" <sven.holcombe@gmail.deleteme.com> wrote:

> Hi there, just a question about concatenating structure array fields where 
> some of the arrays don't have that field initialised. For example:
> 
> s(1).myField = 100;
> s(10).myField = 200;
> 
> [s.myField], or cat(1,s.myfield), both give a result of length 2 since all 
> the other entries are empty.
> 
> I understand you can't have a 1 by 10 array with elements 2 to 9 being empty. 
> How about instead returning those elements as nan?
> 
> Basically, what's the most efficient way for me to concatenate these 
> structure fields, yet retain the indices where each element was found in the 
> structure.
> 
> Cheers,
> Sven.


I would say try initializing your structure with NaNs and then overwrite 
some of them with your existing code.

  s = struct('myField',num2cell(NaN(1,10)));
  s(1).myField = 100;
  s(10).myField = 200;
  [s.myField]
  ans =
     100   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN   200

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.