|
"Diego Lass" <dlISCool@gmail.com> wrote in message <h1e92a$bd7$1@fred.mathworks.com>...
> Hi
> I have a problem with a large matrix, what I want to do is to divide the matrix into 4 submatrices, do some operation then reassemble the submatrix together. A toy example
>
> A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
> A =
>
> 1 2 3
> 3 4 5
> 2 3 4
> 5 1 2
> I want to divide A into ANY approximately equal sized partitions, for example
> 1 2
> 3 4
>
> 3
> 5
>
> 2 3
> 5 1
>
> 4
> 2
>
> then do some operation, say add 2 to each element. Then reassemble them together, to get
>
> 3 4 5
> 5 6 7
> 4 5 6
> 7 3 4
> What is the most efficient way of doing this?
> Thanks
> Diego
The definition of "efficient" is open to many interpretations ... Here is an example that is not particularly fast, but quite flexible:
% your data
A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
myfun = @(X) 1110 * X(1) + X ;
% engine
C = mat2cell(A,[2 2],[2 1]) ;
C = cellfun(myfun, C,'uniformoutput',false) ;
B = cell2mat(C)
hth
Jos
|