Field name with integer value

조회 수: 64 (최근 30일)
Balkar Singh
Balkar Singh 2020년 4월 14일
댓글: Walter Roberson 2020년 4월 15일
How to define a struct with field name integer like 0,1 etc and ! and empty.
Thanks in advance
  댓글 수: 4
Balkar Singh
Balkar Singh 2020년 4월 14일
s = struct('0',{'110000'},'!',{'110001'},' ',{101011});
I want to define struct like this example.
Walter Roberson
Walter Roberson 2020년 4월 14일
Then you will have to use the techniques I described, using an external program to build a corrupt .mat file and load the .mat file in a sufficiently old version of MATLAB.

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

채택된 답변

Steven Lord
Steven Lord 2020년 4월 14일
Depending on what data you're trying to store in this struct, storing the data as variables in a table array (using release R2019b or later, which is when the feature to allow table variable names to contain any character was introduced) may be of interest to you.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 4월 15일
Though it does turn out that the names are limited to 64 characters.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 4월 14일
In order to do that, you will need to write (or find) some code in another programming language, such as C, making use of the published format of .MAT files, and have that code create the internal representation of the structure field using the prohibitted name.
Once you have the resulting .mat file, you will need to load it with an older version of MATLAB. I do not remember exactly which release started to refuse to load .mat files with invalid field names, but what is coming to my mind is that it might have been roughly R2018a. So if, for example, you were to use R2012a or so, you would be able to get MATLAB to read the .mat file that the outside program had created with invalid field names.
You might want to look in the File Exchange as there is a contribution there that is intended to repair files that had invalid field names -- because of course if you have code to repair an invalid field name in a .mat, then that implies that with a small change you could instead have the code deliberately break the .mat .
... In case it has no been clear yet, what I am saying is that MATLAB does not permit field names of that form to be created inside MATLAB, and these days will not even load files that have such names, but if you really need to (for some reason!) you could create them for use in old enough versions of MATLAB.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 4월 14일
T = containers.Map({'0', '1', ''}, {'110000', '110001', '101011'});
T('0')
T('1')
T('')

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by