operation array in cell

i have 2 matrix A and B and cell Z with 13*13 blocks. each blocks have 8*8 pixel.
A=rand(13,13,8,8);
B=rand(13,13,8,8);
i want to process value A and B with each blocks in cell Z.
XY = (Z*A)+B
example, value at A if you see at workspace, start with val(:,:,1,1), there's will be 169 value of A. each value will be process with every blocks of Z to get XY. same with matrix B. total blocks of Z is same with total value of A and B in val {:,:,1,1}.
specificly,
XY{1,1}=Z{1,1}.*A{1,1,1,1} + B{1,1,1,1},
XY{1,2}=Z{1,2}.*A{1,2,1,1}+B{1,2,1,1} until the whole blocks of Z.

댓글 수: 3

Jan
Jan 2013년 3월 5일
What have you tried so far and which problems occurred?
Internazionale
Internazionale 2013년 3월 5일
i am confuse with for.. i tried this program
A= rand(13,13,8,8);
B= rand(13,13,8,8);
Z= mat2cell(Y, [8 8 8 8 8 8 8 8 8 8 8 8 8] , [8 8 8 8 8 8 8 8 8 8 8 8 8]);
for aa=1:13
for bb=1:13
XY{aa,bb}=z{aa,bb}*A(:,:,1,1)+B(:,:,1,1);
end
end
whn i try this one, matlab error. Error using * Too many input arguments.
Internazionale
Internazionale 2013년 3월 5일
Y is matrix 104*104 and i process mat2cell to get Z.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 3월 5일
편집: Andrei Bobrov 2013년 3월 5일

0 개 추천

A1 = permute(A,[3 4 1 2]);
B1 = permute(B,[3 4 1 2]);
XY = Z;
for ii = 1:size(Z,1)
for jj = 1:size(Z,2)
XY{ii,jj} = Z{ii,jj}.*A1(:,:,ii,jj) + B1(:,:,ii,jj);
end
end
ADD variant
Zn = cat(3,Z{:});
s = size(A);
A1 = reshape(permute(A,[3 4 1 2]),s(3),s(4),[]);
B1 = reshape(permute(B,[3 4 1 2]),size(A1));
XY = reshape(num2cell(Zn.*A1+B1,[1 2]),size(Z));

댓글 수: 7

Andrei Bobrov
Andrei Bobrov 2013년 3월 5일
Added more variant
Internazionale
Internazionale 2013년 3월 5일
Undefined function 'times' for input arguments of type 'cell'.
Jan
Jan 2013년 3월 5일
This is a part of an error message. We could suggest an improvement if you post the corresponding code you have used.
Internazionale
Internazionale 2013년 3월 5일
so what i have to do ? i really need this program
eg:
A = randi([3 8],[13,13,8,8]);
B = randi([10 20],[13,13,8,8]);
Z = mat2cell(randi(10,104),8*ones(1,13),8*ones(1,13));
A1 = permute(A,[3 4 1 2]);
B1 = permute(B,[3 4 1 2]);
XY = Z;
s = size(Z);
for ii = 1:s(1)
for jj = 1:s(2)
XY{ii,jj} = Z{ii,jj}.*A1(:,:,ii,jj) + B1(:,:,ii,jj);
end
end
Jan
Jan 2013년 3월 6일
@Internazionale: It would help, if you post the code you are using and a complete copy of the error message. Andrei hast posted two different solutions, and you could potentially have modified one of them, e.g. by a typo. We cannot reliably guess the cause of the error on your computer, so it is your job to explain the circumstances.
Internazionale
Internazionale 2013년 3월 6일
편집: Internazionale 2013년 3월 6일
try to explain, i got an idea but not fully answer. i am still confused because not completed.
A=rand(13,13,8,8);
B=rand(13,13,8,8);
Z=mat2cell(Temp, [16 16 16 16 16 16 16 16 16 16 16 16 16] , ... [16 16 16 16 16 16 16 16 16 16 16 16 16]);
for gg=1:13
for hh=1:13
XY{gg,hh}= (Z{gg,hh}.*A{gg,hh,1,1})+B{gg,hh,1,1};
end
end
this program just for A(:,:,1,1) and B (:,:,1,1). my question, how to use the whole value from A and B. A(:,:,1,1) until A(:,:,8,8) and B(:,:,1,1) until B (:,:,8,8). so we get 64 new cell of XY.

이 질문은 마감되었습니다.

질문:

2013년 3월 5일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by