1.0

1.0 | 4 ratings Rate this file 3 Downloads (last 30 days) File Size: 357 Bytes File ID: #14341

isEmptyStruct

by Johannes Kissel

 

20 Mar 2007 (Updated 20 Mar 2007)

provides the functionality of isempty for structure arrays

| Watch this File

File Information
Description

simple and maybe useful...?

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
20 Mar 2007 Urs (us) Schwarz

there is no help whatsoever - which makes it a no-go to begin with -and- even more worrisome: an is-class type function must(!) return a logical (be scalar or array); contrary to this zealous goal, however, this snippet potentially returns a NAN, which only is defined in the well-known volatile, vain world of FPs...
in summary, you better go back to the drawing board and surprise this community with a spiffy spruced up snipplet...

20 Mar 2007 Dimitri Shvorob

No help = 1 star. Also:
1. The NaN output bit is puzzling.
2. Function name should be lowercase.
3. Doesn't work for structure arrays

clear all
res(2).a = []

res =

1x2 struct array with fields:
    a

>> isemptystruct(res)
??? Illegal right hand side in assignment. Too many elements.

Error in ==> getfield at 38
    f = s.(deblank(strField)); % deblank field name

Error in ==> isEmptyStruct at 12
        if ~isempty(getfield(struct, names{i}))

21 Mar 2007 Johannes Kissel

You reviewers are being extremely negative and offensive. There are no standards that MUST be met. Help text, returning logical results, lowercase function name, structure array support are not required. If you don't like it, don't download it.

22 Mar 2007 dave martin

Boring, inadequate and moldy. The problem with your reply is that one has to download it to know they don't like it, unless they read our reviews.

22 Mar 2007 David Sedarsky

Johannes- Try not to take the reviews personally. A few individuals are a little short with people here. I think they mostly have good intentions (improving the FE) but they come off as arrogant jerks sometimes, and they assume that Matlab help and practices are common knowledge. That said, I think these guys have some good suggestions for improving your code.
Here's a question for you expert reviewer guys: Do you want people to improve their submissions, contribute ideas, and participate here, or just give up and go away?

27 Mar 2007 John D'Errico

To the author - You may know what this code does and how to use it. But without help, nobody else will. Would you throw your newborn child out into the streets unclothed and uneducated? This is effectively what you have done here.

As for the lack of posted standards, this is true, but I hope to see that change. You may post code as you see fit. However you must also recognize that we as reviewers will then see fit to provide unflattering reviews.

Think about how someone willl use your code. There is absolutely no indication what it expects as arguments. I had to read through the code even to decide if I agreed with how it defines an "empty" struct. If you do edit the code, it uses varargin. What & how many arguments will it use or need? What will it return? No hints are given. In effect, your response suggests that anyone who might be interested in using this code must download it, and then waste their time trying to decrypt your code to decide what it does. In my experience, matlab is simple enough to program in that its often far easier to write a tool from scratch than it is to decypher what badly written and documented code does, and then figure out how to use it.

As for David's question, there are vast numbers of tools on the file exchange. Those who wish to find something must sort through much stuff that is effectively of little or no value to them. Reviews provide a facility to decide what is worth a second look. If an author chooses to upload file after file that has no comments, no error checking, code that is buggy and untested, then sadly, yes, I'd rather that author just gives up. Especially if they do so despite poor reviews. All that individual will do is give other users the wrong idea of what good code should look like. Since education is an important part of the file exchange, this is a problem.

On the other hand, authors that improve their submissions, uploading cleaned up versions will get good reviews from me. I'll return to a submission to which I've given a poor review to see if the author has improved it. I'm especially happy to see authors learn to improve their tools and then improve their other codes on the FEX. This means they have learned something.

You may feel that what is here on the file exchange is "as is" code. But it is also an opportunity for novices to learn about programming in matlab. Many novices might go on to work in Matlab or other languages on a profesional basis. So this is an opportunity to learn good programming practices.

As for the code in this submission itself, it can be replaced by a simple one-liner:

A.a = [];
A.B = '';

all(structfun(@isempty,A))
ans =
     1

Finally, my rating for this tool might have been somewhere between a 1 and 2. While I saw no apparent bugs, its also a simple code that lacks any help at all and can be written in one line. This convinces me to call it a 1.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
isempty Johannes Kissel 22 Oct 2008 09:05:11
struct Johannes Kissel 22 Oct 2008 09:05:11
functionality Johannes Kissel 22 Oct 2008 09:05:11
simple Johannes Kissel 22 Oct 2008 09:05:11
utilities Johannes Kissel 22 Oct 2008 09:05:11

Contact us at files@mathworks.com