unction addressStruct(Struct,Field)
if isfield(Struct,Field)
fprintf('The value of the %s field is: ',Field);
disp(Struct.Field);
else
fprintf('Error:%s is not a valid field',Field);
end

 채택된 답변

sedelbx
sedelbx 2023년 5월 17일

0 개 추천

先回去搞清楚,Field 到底是 'code' 这个字符串,还是 code 这个变量名。
S.code = 1;
disp( S.code ) % 正确
Field = 'code';
isfield( S, Field )
disp( S.Field ) % 错误

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App 构建에 대해 자세히 알아보기

태그

질문:

2023년 5월 17일

답변:

2023년 5월 17일

Community Treasure Hunt

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

Start Hunting!