Sum structures with an array 1x1 each one

4 vues (au cours des 30 derniers jours)
Kami
Kami le 26 Juil 2022
Commenté : Kami le 28 Juil 2022
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')

Réponse acceptée

KSSV
KSSV le 26 Juil 2022
Q.O20 = 1;
Q.B3 = 2 ;
Q0h = Q.B3 + Q.O20
Q0h = 3
s = sum(cell2mat(struct2cell(Q)))
s = 3
  1 commentaire
Kami
Kami le 28 Juil 2022
Thanks a lot, it works like charm

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by