Fix help text for newer MATLAB versions

1 view (last 30 days)
I've noticed a change in MATLAB's response to help text. We have equipment that, in the event of an error, automatically generates a trace of internal variables, and creates a MATLAB-formated file that includes help text identifying the machine name, firmware versions and timestamp of the error. We then have scripts that parse the help text and data to generate a human-readable report. We had been using R2010bSP1 for years, but when we updated we find the help() function returns differently. I've tested R2015b and R2016a, below is an example of the change:
data.m:
% Date: Tuesday, September 27, 2016 10:21:14 AM
% Arm B: 0.0.0.3
% Arm M: 2.1.15.8
% FPGA: 86.73.0.0
% Rows: 2048
24 865589 1141503331
25 865589 1112790400
26 865589 1143725291
27 865589 -1002890685
:
2010bSP1:
>> load 'data.m';
>> help('data.m')
Date: Tuesday, September 27, 2016 10:21:14 AM
Arm B: 0.0.0.3
Arm M: 2.1.15.8
FPGA: 86.73.0.0
Rows: 2048
>>
R2015b and R2016a:
>> load 'data.m';
>> help('data.m')
data is a variable of type doub.
>>
Would appreciate any suggestions on how to modify the help() function call to return the help text as before when using newer versions of MATLAB.
Thanks!

Accepted Answer

Steven Lord
Steven Lord on 28 Sep 2016
According to the Release Notes that was a deliberate change introduced in release R2015b. If you want to obtain help for a script or function but you have a variable with the same name in the workspace, the variable wins. The easiest solution is not to create variables with the same name as your script or function files.
  1 Comment
Jon Northup
Jon Northup on 28 Sep 2016
Yes! That's it. Rather than just performing a "load" and allowing MATLAB to create the default Workspace object of the same name, I need to create a new named object set as the load of the data file.
Fix:
>> err_data = load('filename.m');
>> help('filename.m')
Date: Tuesday, September 27, 2016 10:21:14 AM
Arm B: 0.0.0.3
Arm M: 2.1.15.8
FPGA: 86.73.0.0
Rows: 2048
Lost: 0
>>
In the example above, I can then operate on "err_data", and still parse the help text of "filename.m".
The old way worked only in the older MATLAB version. This new approach works in ALL versions. Subtle, but important. Thanks a million!

Sign in to comment.

More Answers (1)

Massimo Zanetti
Massimo Zanetti on 28 Sep 2016
It seems you have a conflict with another file named "data". Try to supply the full path name to the help argument.
  3 Comments
Massimo Zanetti
Massimo Zanetti on 28 Sep 2016
I have R2015b and it works fine. The difference you notice happens when you invoke "help" with a Matlab variable argument. In this case the help provides you the type of the variable. If you invoke "help" with a function name, then it provides you the first commmented lines of the function. It works like this in ALL versions of Matlab.
Jon Northup
Jon Northup on 28 Sep 2016
Our machines generate a text file, not a function. These text files (e.g. filename.txt) begin with a header. Each line of that header starts with a "%" character. The header is then followed by the data. This text file is later renamed with a ".m" extension. Again, there is no function being defined, so H1 is literally line 1 of the file. Then I just load the M file (e.g. filename.m), and a variable object of whatever name I gave the file (e.g. filename 2048x3 double) is created in the Workspace in all cases, every MATLAB version. Given this scenario, the difference I observe is in the return result to help('filename.m'). It's a change that occurred sometime after R2010bSP1.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!