What about the character #?

조회 수: 21 (최근 30일)
Patrik Ek
Patrik Ek 2015년 3월 27일
댓글: Patrik Ek 2015년 3월 27일
Hi,
I wonder if anyone have an idea about the character #. It appears to have no use in matlab and it can neither be used in variable names,
#a = 0; %ERROR!
b.#c = 0; %ERROR!
So, does it have some use that I have still to identify, is it excluded for a reason, ... I am simply curious, what is the thing with the hash?

채택된 답변

Thorsten
Thorsten 2015년 3월 27일
편집: Thorsten 2015년 3월 27일
There is no special thing with the hash. In some script languages it is used as the comment character, and I've seen things like
%# my comment here
You have to use alphanumeric characters for variables, functions etc, and they must not start with a number. Like #, you cannot use $, !, § etc.
So in principle Mathworks could have decided to allow #, but probably because it is not allowed in variable or function names in all programming languages that I know, they decided the same for Matlab.
  댓글 수: 1
Patrik Ek
Patrik Ek 2015년 3월 27일
Ok, I suspected something like that. The main reason that I started to think about it was that I got a crash in some legacy code since the files it parsed suddenly started to get properties like #Things instead of NumThings. Though it may not have been the choice of mine I guess I have little choice in this. A `strrep` solved the issue anyway. Thanks for the explanation.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by