Hello,
I'm writing a script at the moment were all I would like to do is make sure that field definitely exists in a part of a structure I'm taking data from whilst running a 'for'. If it isn't I just want to tell Matlab to 'continue' and skip that part of the loop.
What I'm finding at the moment is that if I use 'isfield' to tell me if a field exists or not within a part of the structure, it keeps telling me that the field does not exist either if it does or doesn't. It consistently returns a '0' instead of a '1' in other words.
The basic code I'm using at this point is:
structure = 'Move'; % name of the structure
for p = 1:21 get_sound_types=['sound_type=fieldnames(' structure '.P' int2str(p) ');']; eval(get_sound_types) for sound_ind = 1:length(sound_type) for bn = 2:4 current_struct_field = ... [structure '.P' int2str(p) '.' sound_type{sound_ind}]; current_block = ['B' int2str(bn)]; existence = isfield(current_struct_field,current_block); if existence == 0 continue %.... (other stuff happens and end statements)
When I try and use this, existence variable always returns a 0, regardless of whether the particular field exists or not. I'm sure I'm doing something silly wrong but I don't know what it could be.
Any help would be great.
Cheers, Chris
Best Answer