Azzera filtri
Azzera filtri

Solve looping for big cell, vector, and summation

2 visualizzazioni (ultimi 30 giorni)
DoinK
DoinK il 14 Giu 2023
Modificato: Matt J il 14 Giu 2023
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?

Risposte (1)

Matt J
Matt J il 14 Giu 2023
Modificato: Matt J il 14 Giu 2023
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 Commenti
DoinK
DoinK il 14 Giu 2023
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 "

Accedi per commentare.

Categorie

Scopri di più su Historical Contests in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by