why does help ignore my comments?
Show older comments
i am not sure when this change was introduced, but it seems that from Matlab 2019a onward (and maybe before), the "help" function is ignoring information i've provided at the top of my function file.
eg,
function [v,d,z]=eof(u)
% EOF empirical orthogonal functions
% [v,d,z]=eof(u)
% time series components stored as column vectors in u.
% v is the matrix of eigenvectors
% d is a diagonal matrix of eigenvalues
% z is the time series of mode amplitudes, stored as column vectors
and i type >> help eof, i get:
eof is a function.
[v, d, z] = eof(u)
rather than the explanation of the function i've included in the top of the m-file. this has always worked (since version 1) so i am not sure what is happening or if this is a bug...
-Derek
10 Comments
dpb
on 22 Apr 2020
I don't see such w/ R2019b nor in any of the releases have installed prior...
Which OS?
BTW, a new function behaves as expected as well as existing...
Have you tried something as simple as
clear help
and/or
which -all help
in case you've somehow managed to alias the builtin TMW function?
Derek Fong
on 22 Apr 2020
Derek Fong
on 22 Apr 2020
Edited: dpb
on 22 Apr 2020
dpb
on 22 Apr 2020
That would definitely seem to be an install/OS issue, then. That's the right path...seems worth a bug report.
Derek Fong
on 22 Apr 2020
Steven Lord
on 22 Apr 2020
My suspicion is that you've shadowed a function that help calls to locate the file whose help text you're trying to display. I don't have a complete list off the top of my head, but maybe check if the what or where functions are shadowed and rename, remove, or move the shadowing functions?
which -all what
which -all where
Walter Roberson
on 22 Apr 2020
These days, help() directly calls
- evalin
- inputname
- isempty
- isscalar
- onCleanup
and some internal functions that I did not track through.
dpb
on 22 Apr 2020
Steven, wouldn't those go away on restart though -- unless it's caused by a startup.m file which should be pretty easy to check?
Wonder if his lookfor finds the H1 line?
Walter Roberson
on 22 Apr 2020
... There appear to be entire classes devoted to processing help information.
Answers (1)
Image Analyst
on 22 Apr 2020
The comments need to be the first thing in the file, not within the body of the function (because there are likely to be tons of those):
% EOF empirical orthogonal functions
% [v,d,z]=eof(u)
% time series components stored as column vectors in u.
% v is the matrix of eigenvectors
% d is a diagonal matrix of eigenvalues
% z is the time series of mode amplitudes, stored as column vectors
function [v,d,z]=eof(u)
8 Comments
Derek Fong
on 22 Apr 2020
Image Analyst
on 22 Apr 2020
Worked for me. If it's:
% EOF empirical orthogonal functions
% [v,d,z]=eof(u)
% time series components stored as column vectors in u.
% v is the matrix of eigenvectors
% d is a diagonal matrix of eigenvalues
% z is the time series of mode amplitudes, stored as column vectors
function [v,d,z]=eof(u)
then I see this in R2020a:
>> help eof
eof empirical orthogonal functions
[v,d,z]=eof(u)
time series components stored as column vectors in u.
v is the matrix of eigenvectors
d is a diagonal matrix of eigenvalues
z is the time series of mode amplitudes, stored as column vectors
Actually I can put it after the function line, and I still see the same thing. So I think it's just you Derek. Call tech support and ask them.
Derek Fong
on 22 Apr 2020
dpb
on 22 Apr 2020
That's not what the doc says (nor what TMW-supplied functions do and I didn't realize that would ever work that way).
"Create help text by inserting comments at the beginning of your program. If your program includes a function, position the help text immediately below the function definition line (the line with the function keyword). ..."
lookfor uses the H1 line; and the help text stops with the first blank line (no comment character). Comments beyond that are ignored.
Rik
on 22 Apr 2020
@Image Analyst:
I just tested it on Matlab 6.5, and even on that release it works if you put the help text inside the first function. I can't recall this ever having been an issue for me, can you elaborate on what issues might arise if you don't use your proposed layout?
Derek Fong
on 22 Apr 2020
Derek Fong
on 22 Apr 2020
dpb
on 22 Apr 2020
Since it also works for scripts, I suppose it simply starts with the first comment line in the file and ignores whether there is/isn't a function statement entirely. Hence it would work with whichever sequence is used; I just had always followed the suggested pattern and never tried anything different with functions.
Coming from Fortran, nothing exists outside a program unit so having comments in a file outside a function is "just wrong!" :)
Categories
Find more on Entering Commands in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!