フィルターのクリア

Solve looping for big cell, vector, and summation

2 ビュー (過去 30 日間)
DoinK
DoinK 2023 年 6 月 14 日
編集済み: Matt J 2023 年 6 月 14 日
I have Z, Z is cell (1*1000) and for i=1:1000 size(Z{i}) is 1*1008
I need to do the summation until 1000, start from 1, i can do it manually but it will be long until 1000.
The code is like this,
p1=sum(reshape(Z{1},[],4),1) %Z{1} is 1*1008, from 1008 column reshape to 4 column
%4*column1
%5*column2
%6*column3
%7*column4
for i=1:4
f=(i+3)*p1(i) % x*p(x)
h(i)= f %size(1*4)
end
sum(h)
Repeat,
p2=sum(reshape(Z{2},[],4),1)
%8*column1
%9*column2
%10*column3
%11*column4
for j=1:4
f=(j+7)*p1(j) % x*p(x)
h(j)= f %size(1*4)
end
sum(h)
How to create a looping until p1000?

回答 (1 件)

Matt J
Matt J 2023 年 6 月 14 日
編集済み: Matt J 2023 年 6 月 14 日
Z=repmat({rand(1,1008)}, 1,1000); whos Z %Fake input data
Name Size Bytes Class Attributes Z 1x1000 8168000 cell
Z=reshape(cat(3,Z{:}) ,[],4,numel(Z));
p=sum(Z,1);
w=reshape(0:numel(p)-1,1,4,[]);
result = squeeze( sum( p.*w,2) ); whos result
Name Size Bytes Class Attributes result 1000x1 8000 double
  2 件のコメント
DoinK
DoinK 2023 年 6 月 14 日
The last result is like this Sir,
w(:,:,63000) =
251996 251997 251998 251999
And pop out error message :
"Arrays have incompatible sizes for this operation.
Related documentation "
Matt J
Matt J 2023 年 6 月 14 日
Should be fixed now.

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

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by