## find index of empty field in a structure array, vectoried

### find index of empty field in a structure array, vectoried

Hello,
let
x(1).a = 1; x(2).a =[];x(3).a=[];x(4).a=3.4
I would like to get an index array returned to indicate location of
empty element. for this example,
indx = [0 1 1 0];

Is there an one liner for this?

--wsun

### find index of empty field in a structure array, vectoried

Here you go:

%---
x(1).a = 1; x(2).a =[]; x(3).a =[]; x(4).a = 3.4;
cellfun('isempty',{x.a})
%---

Ghassan

> Hello,
> let
> x(1).a = 1; x(2).a =[];x(3).a=[];x(4).a=3.4
> I would like to get an index array returned to indicate location of
> empty element. for this example,
> indx = [0 1 1 0];

> Is there an one liner for this?

> --wsun

### find index of empty field in a structure array, vectoried

Ghassan:
Thank you very much. It's what I needed.

--wsun

> Here you go:

> %---
> x(1).a = 1; x(2).a =[]; x(3).a =[]; x(4).a = 3.4;
> cellfun('isempty',{x.a})
> %---

> Ghassan

> > Hello,
> > let
> > x(1).a = 1; x(2).a =[];x(3).a=[];x(4).a=3.4
> > I would like to get an index array returned to indicate location of
> > empty element. for this example,
> > indx = [0 1 1 0];

> > Is there an one liner for this?

> > --wsun

This script causes Matlab to report a segmentation violation:

a = struct ('x', cell (0,1));
if a.x
end

Details:
Windows NT4
MATLAB Version 5.1.0.421 on PCWIN

Regards,
--
Jeremy Henty
Research Engineer
Olivetti and Oracle Research Laboratory