필터 지우기
필터 지우기

Dynamic struct names with strings.

조회 수: 3 (최근 30일)
BdS
BdS 2019년 4월 24일
편집: James Tursa 2019년 4월 24일
Hi
I have got a 4x1 cell (named= RankFileNames) with the following chars
'0_1_workspace_20190410.mat'
'0_2_workspace_20190228.mat'
'1_1_workspace_sectNorm_20190228.mat'
'1_2_workspace_sectNorm_20190410.mat'
I would like create the following dynamic struct: RawData.(RankFileNames{1,1}).factorlist=[2 4 5 3] next interation
RawData.(RankFileNames{2,1}).factorlist=[2 4 5 3] and so one
However, Matlab returns the following error: Invalid field name: '0_1_workspace_20190410.mat'.
I am not interested in getting the apostrophes. Desired solution: RawData.0_1_workspace_20190410.mat.factorlist and RawData.0_2_workspace_20190228.mat.factorlist
Do you have any hints? thank you in advance.

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 24일
You cannot do that. Field names cannot begin with a number or an underscore. You would need to prefix the file name with something.
  댓글 수: 2
Guillaume
Guillaume 2019년 4월 24일
field names also can't have a .
The error message is entirely correct, your field names are invalid.
You could use matlab.lang.makeValidName to make valid field names out of your strings. This would change '1_1_workspace_sectNorm_20190228.mat' into 'x1_1_workspace_sectNorm_20190228_mat'
Walter Roberson
Walter Roberson 2019년 4월 24일
.. I still think it was a mistake for them to have gone from a simple function name such as genvarname() for the rather forgettable matlab.lang.makeValidName()

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by