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 :)
@Carsten--The OptionalDataException appears to be associated exclusively with serializable objects. I don't know why this is happening, but you could presumably get around this problem by setting 'serialize' to false and converting the payload data to int8 (see last example in jtcp.m header). Would this be an option for you?
i have a problem using the jTPC read function.
I get an 'java.io.OptionalDataException' if i try to use the read function in a timer function that works in a GUI.
If the timers period is >0.3 seconds it works without problems but i want a faster update.
The code that should be updated under 0.3 seconds is:
mssgs = jtcp('read',jTcpObj);
mssg = mssgs(1); %mssgs is a cell array
Hope you can help me, thank you