Access Time Table elements in a struct array

4 ビュー (過去 30 日間)
Katarina Godden
Katarina Godden 2018 年 5 月 31 日
コメント済み: Katarina Godden 2018 年 6 月 9 日
I have a struct array with 603 elements and 7 fields.
One field contains a time table with 60 variables.
I want to access specific elements in the last row of all 603 time tables, preferably as an array size(603,specificElements) without running a for loop or using getfield.
this is my current code
for k = 1:603
temp(k,:) = getfield(All_Nodes,{k,1},'ProvisionedPlanCount',{17,1:60});
end
then I convert the resulting table to an array and continue in my endeavors.

回答 (1 件)

sloppydisk
sloppydisk 2018 年 5 月 31 日
編集済み: sloppydisk 2018 年 5 月 31 日
You could use arrayfun to put the elements you need in cells and then combine them using cell2mat:
a(1:5) = struct('myField', reshape(1:100, 10, 10));
elemCell = cell2mat(arrayfun(@(x) x.myField(end, end-5:end), a, 'UniformOutput', false))
  1 件のコメント
Katarina Godden
Katarina Godden 2018 年 6 月 9 日
I am dealing with TimeTables in "myField" not an array.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by