Code covered by the BSD License  

Highlights from
UNEMPTY

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

UNEMPTY

by Andreas

 

22 Mar 2005 (Updated 23 Mar 2005)

Sets empty fields in a structure to a defined value.

| 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

Contact us at files@mathworks.com