how to replace the values of one matrix to another

c=[1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
f=[ 1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16]
12 13 17 18]
f matrix is divided into 2 X 2 matrix ie first block is
ie
f(1,1) f(1,2)
f(2,1) f(2,2)
next block is
f(1,3) f(1,4)
f(2,3) f(2,4)
f matrix is divided into block for all values present
every 4 value from c matrix is added to this 2X2 matrix formed from f matrix
ie c(1,1) is added to f(1,1) and c(1,2) is added to f(1,2)
and c(1,3) is added to f(2,1) and c(1,4) is added to f(2,2)
ie to the first block.. next 4 values from c block is added to
next block ie c(1,5) to c(1,8) is added to
f(1,3) & f(1,4) & f(2,3) & f(2,4) please help me i am not able to define the loops properly
Thanks in advance

답변 (2개)

Image Analyst
Image Analyst 2012년 11월 27일

0 개 추천

You can use blockproc().
Andrei Bobrov
Andrei Bobrov 2012년 11월 27일

0 개 추천

f=[ 1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16]
c=[1;1]*(1:8);
f2 = permute(reshape(f,[2 2 2 2]),[3 1 4 2]);
out0 = f2 + reshape(c.',size(f2));
out = reshape(permute(out0,[2 3 1 4 ]),size(f,1),[]);

카테고리

태그

질문:

2012년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by