0

Is there a way in Matlab or Octave to check if a string is or contains a comment? Some similar to iscomment().

It is easy to check in the case we deal with comment lines where the comment identifier is at the beginning, using first strtrim() for blank elimination and then strfind() for search the comment identifier. But the problem is difficult when a comment is after a sentence or when the comment character is used in the string with other meaning, as, for example, in the fprintf() function for data format definition

Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
jgpallero
  • 183
  • 1
  • 6
  • Just wondering: Why do you want to know this? Do you mean an actual [string](http://www.mathworks.se/help/matlab/ref/strings.html), or a line of code? – Stewie Griffin Nov 04 '14 at 14:20
  • I need to read a data file, in which I want to permit the user put comments (and blank lines) – jgpallero Nov 04 '14 at 14:27
  • have you seen this: http://blogs.mathworks.com/pick/2009/07/17/want-to-get-rid-of-your-code-comments/ and http://www.mathworks.com/matlabcentral/answers/110086-how-to-delete-all-the-commented-content-in-a-m-file, both refer to: http://www.mathworks.com/matlabcentral/fileexchange/4645---matlab-comment-stripping-toolbox – Amro Nov 04 '14 at 14:36
  • `textscan` + `'commentStyle'` is another option for some cases. – nkjt Nov 04 '14 at 16:25

0 Answers0