3 views (last 30 days)

dpb
on 7 Jul 2017

Edited: dpb
on 8 Jul 2017

Something like this you mean:

>> x=reshape(1:9,3,3) % starting sample input array

x =

1 4 7

2 5 8

3 6 9

>> N=2; % choose a multiplier size factor

>> xnew=cell2mat(arrayfun(@(x) repmat(x,N,N),x,'uniform',0))

xnew =

1 1 4 4 7 7

1 1 4 4 7 7

2 2 5 5 8 8

2 2 5 5 8 8

3 3 6 6 9 9

3 3 6 6 9 9

>>

ADDENDUM To divide down is as you surmise, just use N as divisor in the anonymous function--for the same x

>> cell2mat(arrayfun(@(x) repmat(x,N,N)/N,x,'uniform',0))

ans =

0.5000 0.5000 2.0000 2.0000 3.5000 3.5000

0.5000 0.5000 2.0000 2.0000 3.5000 3.5000

1.0000 1.0000 2.5000 2.5000 4.0000 4.0000

1.0000 1.0000 2.5000 2.5000 4.0000 4.0000

1.5000 1.5000 3.0000 3.0000 4.5000 4.5000

1.5000 1.5000 3.0000 3.0000 4.5000 4.5000

>>

ADDENDUM 2: Of course, if N is constant as above, it can come outside the anonymous function--

cell2mat(arrayfun(@(x) repmat(x,N,N),x,'uniform',0))/N

If it were a positional transform, the anonymous function could have a second argument of size(x) if need be or the dot division operator or automagic singleton expansion in later versions could come into play depending on just what a particular transformation looked like.

Geoff Hayes
on 7 Jul 2017

Andrew - what have you tried so far? Suppose mtx1 is your 600x600 matrix and mtx2 is your 6000x6000 matrix. The mapping of your elements from mtx1 to mtx2 is as follows

mtx1(1,1) --> mtx2(1:10,1:10)

mtx1(1,2) --> mtx2(1:10, 11:20)

mtx1(1,3) --> mtx2(1:10,21:30)

...

mtx1(2,1) --> mtx2(11:20,1:10)

...

mtx1(3,1) -->mtx2(21:30,1:10)

So one way to do this, is to iterate over each row and column of mtx1 and then map it to the correct "block" of mtx2 probably something like

mtx2((r-1)*10+1:r*10,(c-1)*10+1:c*10) = mtx1(u,v)/10;

where r and c are the indices to the current row and column respectively.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/347775-divide-and-expand-matrix#comment_467352

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/347775-divide-and-expand-matrix#comment_467352

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/347775-divide-and-expand-matrix#comment_467354

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/347775-divide-and-expand-matrix#comment_467354

Sign in to comment.