MATLAB Answers

0

Cleaning-up Code With Comments

Steve 님이 질문을 제출함. 9 Apr 2013
I remember there was a command to add tildes to the end of a line of comments so as to distinguish it more from the actual code. I think I was using 2009b at the time and now I'm using 2007b. Was I hallucinating?

  댓글 수: 0

로그인 to comment.

답변 수: 5

Mahdi 님의 답변 9 Apr 2013

To add comments into a code, simply use the percent (%) sign. For example
for i=1:10
x=i % Makes x equal to i
end

  댓글 수: 0

로그인 to comment.


Razvan 님의 답변 9 Apr 2013

Control + R comments a line and Control + T removes the comment marker from the begining of a line. The comments start with the percent sign %. I have no idea in which version of Matlab these shortcuts were introduced...

  댓글 수: 0

로그인 to comment.


Image Analyst 님의 답변 9 Apr 2013

Tildes mean to ignore certain return arguments:
[folder, ~, ~] = fileparts(mfilename('fullpath'))
which doesn't return anything for the base filename, or the extension. Introduced somewhat recently.
Percent symbol means the rest of the line after the percent symbol is to be considered as a comment. Can be at the start of a line of text, on the line after the code statement is done.
% This is a comment on it's own line.
magic(4) % This is a comment after a line of code.

  댓글 수: 0

로그인 to comment.


bym 님의 답변 9 Apr 2013

%{
were you thinking
of multiple
lines of
comments? (curly
braces,not tildes)
}%

  댓글 수: 0

로그인 to comment.


Steve 님의 답변 10 Apr 2013

Here is an example of some code that I previously used.
i
%=========================END OF SIMULATION================================
%--------------------------Root Locus Plot---------------------------------
%Details: Plots the phugoid and short period mode for the CV880M.
%Configure results window number 4
figure(4)
I don't remember how but for 'END OF SIMULATION' and 'Root Locus Plot' I remember that I didn't simply smash the = and - keys to get them centered. I used some other shortcut key.

  댓글 수: 0

로그인 to comment.



Translated by