数据结构中字段的引用问题。

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

 Akzeptierte Antwort

sedelbx
sedelbx am 17 Mai 2023

0 Stimmen

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

Weitere Antworten (0)

Kategorien

Mehr zu App 构建 finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Mai 2023

Beantwortet:

am 17 Mai 2023

Community Treasure Hunt

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

Start Hunting!