Be the first to rate this file! 8 downloads (last 30 days) File Size: 1.56 KB File ID: #7223

UNEMPTY

by Andreas

 

22 Mar 2005 (Updated 23 Mar 2005)

Code covered by BSD License  

Sets empty fields in a structure to a defined value.

Download Now | Watch this File

File Information
Description

This function is useful if numeric values from a structure array are to be extracted using the notion M = S.field] UNEMPTY makes sure that empty matrices in the structure do not affect the size of M.
 
S = unempty(C) sets all occurences of empty matrices in all fields of C to NaN.
 
[S,nc] = unempty(C) reports the number of changed fields in nc.
 
S=unempty(C,F) sets in a structure array all occurences of empty matrices for field F to NaN.

S=unempty(C,F,value) sets all occurences of empty fields to value.
 
Example:

S=[struct('f',1) struct('f',2) struct('f',[]) ];
disp([S.f]) % size is different from S
   1 2
S = unempty(S);
disp([S.f]) % size is the same as S
   1 2 NaN

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
24 Mar 2005 Jos x@y.z

More effective:
% the data
S=[struct('f',1) struct('f',2) struct('f',[]) ];
% insert NaNs
[X{1:length(S)}] = deal(S.f) ;
X{cellfun('isempty',X)} = NaN ;
% the result
SS = [X{:}] ;

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
structures Andreas 22 Oct 2008 07:43:55
cell arrays Andreas 22 Oct 2008 07:43:55
utilities Andreas 22 Oct 2008 07:43:55
empty Andreas 22 Oct 2008 07:43:55
fields Andreas 22 Oct 2008 07:43:55
 

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