Very useful function, but message output is not conducive to machine-processing. It would be helpful to have an option to return only the non-matching field names per se.
I didn't choose to modify the function code, but instead wrote a helper function which extracts the field names from the output messages. Here's the core logic, hope it may be helpful to someone..
Here's an example of the message output from comp_struct():
>>st_1.NAME = 'abc';
>>st_2.NAME = 'def';
>>[~,cv_st_1_msgs] = comp_struct(st_1,st_2,0,0,0,'','',0)
cv_st_1_msgs = '(1).NAME and (1).NAME do not match'
We want to extract 'NAME' from this string. Using free utility Expresso, I
developed a regular expression to capture the first occurence of 'NAME'.
% Declare regular expression to capture field name from comp_struct()
% message output:
regex = '\(.*\)\.(.*)\sand';
% Apply (regex) to all comp_struct output strings & return the capture groups as an (N x 1) cell vector of doubly-nested cell vectors containing the token match.
cv_cv_cv_fieldnames = regexp(cv_messages,regex,'tokens');
This utility doesn't work consistently for me. Specific problems:
1) Documentation states that file name is taken as the file specification. However, the function occasionally generates errors like the following:
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in dlmcell (line 98)
fprintf() requires a file handle as first argument. I'll therefore have to dig into this F/E function & possibly modify.
2) This function doesn't return any values, even on error. Instead, it prints error messages at the command-line & returns normally. This is poor programming practice & makes it inconvenient to deploy within another function where error-detection must be handled programmatically.
Thank you Bobby! for your excellent implementation of this classic design pattern. I especially appreciate your extensive documentation & excellent, highly-descriptive coding style.
5-stars well-deserved. If only all MATLAB code could look like this! Highly recommended.
Very helpful utility! Highly recommended! I launch this browser from a Matlab toolbar button.
Just a couple of minor notes :
(1) I commented-out browse.m lines 24-31 to suppress annoying error messages about bioinfo toolbox; maybe please wrap those in a conditional, if possible?
(2) Long identifier strings can easily get cut off & scrolling within the columns is no fun. Maybe please consider resizing window contents when window is resized?
Otherwise, great work! Thank you very much for this submission :)
a little Update to your Code:
you can also use function calls like "map.isKey(..)" and avoid the according error, if you add the following at beginning of the function "subsref(M, S)":
if ~strcmp(S(1).type, '()')
v = builtin('subsref', M, S);
I would like to associate my uiextras.Panel with a window that displays some help text. I struggle to find a way how this can be done. I guess I could add this as a child to the panel, but since all panels look differently it is difficult to come up with a homogeneous way of doing this.
The simplest would be to add a callback to the title of the panel or, perhaps more elegant, add a button with a question mark all the way to the right of the top of the panel, i.e. on the opposite side of the title text, that has a callback to the help window. Is any of this possible?