필터 지우기
필터 지우기

matlab struct initialization issue

조회 수: 3 (최근 30일)
Anmol Pardeshi
Anmol Pardeshi 2020년 11월 4일
댓글: Ameer Hamza 2020년 11월 4일
I'm trying to initialize a strut which would have fields that represent age groups like <39, 40-49, 50-59 and so on. So I tried the following
x = struct('below39',{},'AG 40 to 49',{}); but it gives me an invalied field name error. I also tried
x = struct('below39',{}); and that worked. I'm not sure why is this an issue. Any insights would eb helpful.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 4일
편집: Ameer Hamza 2020년 11월 4일
In MATLAB, the struct fieldnames cannot have spaces. The following will work
x = struct('below39',{},'AG_40_to_49',{})
Read here about rules to for creating a fieldname: https://www.mathworks.com/help/matlab/ref/struct.html#d122e1258552
  댓글 수: 3
per isakson
per isakson 2020년 11월 4일
See matlab.lang.makeValidName and isvarname()
Ameer Hamza
Ameer Hamza 2020년 11월 4일
@Anmol Pardeshi, yes. The link mentions the rules to define a fieldname.
@Per Isakson, Thanks for the information.

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

추가 답변 (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