can i access field by using values in structure?
1 回表示 (過去 30 日間)
古いコメントを表示
if there is some structure with different fields and the field also have lots of values . can we access field by using value?
like we don't know anything about struct or field , we just have values in our hand so can we find which field contains certain value?
0 件のコメント
採用された回答
KSSV
2022 年 10 月 10 日
S = struct ;
S.name = {'Tom' 'Dick' 'Harry'} ;
S.sex = {'M' 'M' 'F'} ;
S.Age = [16 17 18] ;
val = 'F' ;
fields = fieldnames(S) ;
for i = 1:length(fields)
vals = getfield(S,fields{i}) ;
[c,ia]= ismember(vals,val) ;
if any(c)
fprintf('given value is present in %s field\n',fields{i}) ;
end
end
5 件のコメント
その他の回答 (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!