Creating variable whose name is part of a string
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a .mat file as an input for my function and I know that it contains a struct, but I don't know exactly the name of that struct (is different from file to file).
>> s = load('myFile');
>> name = fieldnames(s)
name =
unknown
where unknown depends on the .mat file input I have.
How can I access s.unknown.X? (I know for sure that unknown have an X and Y field, whatever the input might be)
댓글 수: 0
채택된 답변
Robert Cumming
2013년 6월 13일
Basically - dont use eval - its bad! use dynamic fieldnames instead! :)
댓글 수: 4
Jan
2013년 6월 13일
I agree with Robert: Do not create variables dynamically. It would work, but increase the complexity of the code without any real benefit, slows down Matlab by impeding the JIT acceleration, and makes debugging much harder.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!