フィルターのクリア

Looping over table variable to access structure

3 ビュー (過去 30 日間)
roblocks
roblocks 2016 年 5 月 19 日
コメント済み: roblocks 2016 年 5 月 19 日
Dear All,
Suppose you have a table and structure of the following format
A code size
obs1 an 10
obs2 bg 8
obs3 cf 5
and a structure:
structurename.an
sturcturename.ag
sturcturename.cf
containing some stuff. Assume code is unique and any codes in the table are also part of the structure. I would now like to access the first n structure variables by size defined in table. So for example the first largest to I want matlab to take "an" and "ag" and then compute something with it. What is the best way to loop through tables?
Thanks in advance!
Best

採用された回答

Guillaume
Guillaume 2016 年 5 月 19 日
1. Sort your table by decreasing size:
tsorted = sortrows(t, 'size', 'descend');
2. Simply iterate over the rows and use dynamic field names to access your structure:
for row = 1:n
val = structurename.(sortedt{row, 'size'});
%do something with val
end
  1 件のコメント
roblocks
roblocks 2016 年 5 月 19 日
thx again Guillaume

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by