help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to test empty struct?


From: John W. Eaton
Subject: how to test empty struct?
Date: Thu, 28 Oct 2010 17:19:12 -0400

On 28-Oct-2010, John W. Eaton wrote:

| On 28-Oct-2010, Eric Chassande-Mottin wrote:
| 
| | how does one test that a structure array is empty?
| | it does not seem possible with the usual function
| | for vectors.
| | 
| | a=struct; length(a), isempty(a)
| | ans =  1
| | ans = 0
| 
| If you want an empty struct array, you have to write
| 
|   struct ([])
| 
| Things are done this way for Matlab compatibility.

It occurred to me you might also be asking how to find the number of
fields in a structure instead of asking about its array dimensions.
There is no function specifically for that, so you currently have to
write something like

  numel (fieldnames (s))

But maybe it would be worth having a separate function like numfields
to do this job.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]