필터 지우기
필터 지우기

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 CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by