why does help ignore my comments?

조회 수: 7 (최근 30일)
Derek Fong
Derek Fong 2020년 4월 22일
댓글: Walter Roberson 2020년 4월 22일
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
dpb
dpb 2020년 4월 22일
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 2020년 4월 22일
... There appear to be entire classes devoted to processing help information.

댓글을 달려면 로그인하십시오.

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by