Sum structures with an array 1x1 each one

조회 수: 4 (최근 30일)
Kami
Kami 2022년 7월 26일
댓글: Kami 2022년 7월 28일
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일
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개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by