How to sum field elements inside a large structure array.

I have mat. data file with the follwoing spes:
data=load('load_models.mat', 'models')
data =
struct with fields:
models: {1000×1 cell}
>> models
models =
1000×1 cell array
0 {1440×3 double}
1 {1440×3 double}
: :
999 {1440×3 double}
Each cell of the 1000 rows contais (1440×3) matrix.
What I want to get is a new array of size (1440×3), where the elemnts of the new array is the summation of corresponding individal feild elements of the whole 1000×1 struct.
Any fuction of example approch can help me achive my opjective?

 採用された回答

Image Analyst
Image Analyst 2021 年 6 月 5 日

0 投票

Try mean() and cell2mat(). If that does not work, can you attach your .mat file with the paperclip icon (if it's less than 5 MB in size).

3 件のコメント

Nasser Alqurishi
Nasser Alqurishi 2021 年 6 月 5 日
編集済み: Nasser Alqurishi 2021 年 6 月 5 日
Mean() and sum() didn't work. The cell2mat reshape the aray to size (1440000 x 3). the new array size I want is (1440×3) where the 1440 represnet the # of minites in a day and 3 columns values are the cofficents of the some models.
Image Analyst
Image Analyst 2021 年 6 月 5 日
Does this work for you:
fileName = 'active_power_load_models.mat'
s = load(fileName)
ca = s.p_zip_models;
theSums = zeros(1440, 3);
for k = 1 : length(ca)
thisArray = ca{k};
theSums = theSums + thisArray;
end
Nasser Alqurishi
Nasser Alqurishi 2021 年 6 月 5 日
It worked perfeclty!. Many thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by