Access lower level fields in structure

3 ビュー (過去 30 日間)
Mark Krzysztopik
Mark Krzysztopik 2019 年 10 月 25 日
回答済み: galaxy 2019 年 10 月 25 日
I have a structure that is setup as follows.
foo.check.W = 1
foo.check1.W = 2
foo.check2.W = 3
I would like to quickly grab all the data in foo.(all fields).W and save it to an array that i can plot it. I know i could do:
fnames = fieldnames(foo)
for i =1:length(fnames)
Wdata(i) = foo.(fieldnames(i)).W
end
But would like to know if there's a quick way to access the data without using loops.

採用された回答

galaxy
galaxy 2019 年 10 月 25 日
Let 's try
sm = table2array(cell2table(struct2cell(foo)));
Wdata = [sm(:).W];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by