Reguarding 'assignin' acceptable name for variable.

18 ビュー (過去 30 日間)
Robert
Robert 2017 年 7 月 14 日
コメント済み: Walter Roberson 2019 年 5 月 4 日
Hello everybody,
Quick question, are there any specific characters that give error for 'assignin' in the variable name?
I am asking as the acceptability of a variable name looks random. In the latest trial I tried assigning a variable name as: '280617_SC_Ger' but I got an error. If I change this to 'SCGer_280617' it works.
Any Ideas?
Thank you for your answers!
%% Part of code of interest: assignin('base',sprintf('%s_Raw_Data',varname), output)
%% Error: Error using assignin Invalid variable name "280617_SC_Ger_Raw_Data" in ASSIGNIN.
  2 件のコメント
Stephen23
Stephen23 2017 年 7 月 14 日
編集済み: Stephen23 2017 年 7 月 14 日
Reading the MATLAB documentation is faster than logging onto some internet forum and asking strangers how basic MATLAB features work:
You should also avoid magically creating or accessing variable names. Read this to know why:
Guillaume
Guillaume 2017 年 7 月 14 日
More than the variable name, the real issue here is the use of assignin. Usually a good indication that the code is badly designed and very brittle.
On the subject of variable names, very few programming languages allow variable names that start with a number.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2017 年 7 月 14 日
In MATLAB the variable names never start with numbers ...it should be always a character....after character you can use number.
280617_SC_Ger this as a variable name not allowed, because it starts with number...
SCGer_280617 this as a variable name allowed, as it starts with character....
  3 件のコメント
Steven Lord
Steven Lord 2017 年 7 月 14 日
You can check if a particular identifier is a valid variable name using the isvarname function.
Walter Roberson
Walter Roberson 2019 年 5 月 4 日
Please start a new Question for this, and post your opt705, and show the code that is calling it -- preferably enough for us to be able to reproduce the problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by