Passing a string to a function
조회 수: 1 (최근 30일)
이전 댓글 표시
I have created several structures based on my data using eval. The names of the structures and the names of the fields are stored in seperate arrays and the names can be different depending on the data. How can I pass these strings into a functin such as fieldnames? I keep gettting errors that the input arguments cannot be 'cell' or 'char'. So if the name of my struct is in name(1,1) how can i run fieldnames(name(1,1))
댓글 수: 0
채택된 답변
Wayne King
2012년 3월 20일
namestruct = 'test';
test = struct('x',randn(100,1),'y',randn(100,1));
namez = fieldnames(eval(namestruct))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!