Sum structures with an array 1x1 each one

Hi, i amtrying to sum an structure but manually wil be considerable large
Q.O20 = 1
Q.B3 = 2
Q0h = Q.B3 + Q.O20;
It is quite easy with few structures but i have a problem, as this structure depending on the experiment can be up to 35 variables
There is anyway to sum all Q values from the structure? I have tried this but won't get the values
Q0h = sum(Q.Variables)
Q0h = sum(Q,'all')

 採用された回答

KSSV
KSSV 2022 年 7 月 26 日

0 投票

Q.O20 = 1;
Q.B3 = 2 ;
Q0h = Q.B3 + Q.O20
Q0h = 3
s = sum(cell2mat(struct2cell(Q)))
s = 3

1 件のコメント

Kami
Kami 2022 年 7 月 28 日
Thanks a lot, it works like charm

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 7 月 26 日

コメント済み:

2022 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by