필터 지우기
필터 지우기

How do I convert a field name into a variable name in a script?

조회 수: 3 (최근 30일)
Alexander
Alexander 2023년 11월 22일
편집: Stephen23 2023년 11월 22일
I've loaded a matfile structure with unknown fields and want to write a script that processes the data in the fields.
>> S = load('matfile.mat');
>> fields = fieldnames(S)
fields =
1×1 cell array
{'InterestingStuff'}
InterestingStuff is an array of doubles. To access it not knowing the field name,
fields{1}(1,1)
for instance doesn't work, neither does
string(fields{1})(1,1)
What can I use in a script?
  댓글 수: 1
Stephen23
Stephen23 2023년 11월 22일
편집: Stephen23 2023년 11월 22일
So you are using a structure but don't know how to define the fieldname dynamically... a good place to start is to simply open the STRUCT documentation:
and then scroll to the bottom where you will find lists of related functions and articles, like this one:

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 11월 22일
S.(fields{1})
That is, structure (or object) name, then "." then ( then an expression that evaluates to a character vector or string scalar, then )

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by