matlab 矩阵变换

View Code
1 function result = matrix_change(X,m1,n1)
2 %需要变换的矩阵,分割成m1*n1区域求均值
3 [m,n] = size(X);
4 solution=reshape(sum(reshape(X,m1,[])),[],n);
5 solution_z=reshape(sum(reshape(solution',n1,[])),[],m/m1);
6 result=solution_z'/(m1*n1);

调用:

View Code
clc;
A
=[1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8]
result
= matrix_change(A,2,2);
result
*2*2
result

图示:

matrix_change(X,m1,n1)

X:即为输入的原始矩阵;

分成m1*n1的图块求均值;

PS:matlab的reshape函数配合sum,转置,mean等函数对于矩阵的变换很强大,有些东西自己可以试试,函数就这些,但用法很多。

原文地址:https://www.cnblogs.com/sunwufan/p/2163959.html