sum filed in struct

1 次查看(过去 30 天)
Luca Re
Luca Re 2023-6-3
编辑: Paul 2023-6-6
>>Sis.PV
ans =
20
ans =
20
ans =
20
Sis =
1×82 struct array with fields:
Name
On
PV
>> sum(Sis.PV)
Error using sum
Too many input arguments.

采纳的回答

Paul
Paul 2023-6-3
编辑:Paul 2023-6-6
% example data
Sis.PV = 20;
% Sis.PV = repmat(Sis.PV,1,82); % original incorrect line, expanded the field instead of the struct
Sis = repmat(Sis,1,82); % correct line, expands the struct
Sis
Sis = 1×82 struct array with fields:
PV
sum([Sis.PV])
ans = 1640
See this tutorial on how to use comma separated lists.
  3 个评论
Paul
Paul 2023-6-3
Yes, I used []. Read the tutorial at the link I provided in the answer for more info. And/or search the doc for "comma-separated lists".
Paul
Paul 2023-6-6
I just realized I had a mistake in my example. I'll edit the Answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by