why does help ignore my comments?

7 visualizzazioni (ultimi 30 giorni)
Derek Fong
Derek Fong il 22 Apr 2020
Commentato: Walter Roberson il 22 Apr 2020
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 Commenti
dpb
dpb il 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
Walter Roberson il 22 Apr 2020
... There appear to be entire classes devoted to processing help information.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 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 Commenti
Derek Fong
Derek Fong il 22 Apr 2020
the only restriction (prior to this) i believe existed is that the help "displayed" stops with the first line without a comment.
dpb
dpb il 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!" :)

Accedi per commentare.

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by