Matrix 将模式应用于八度矩阵
我在用八度音阶。我有一个随机的MxN矩阵。我想使用预定义模式将矩阵中的某些值设置为零:Matrix 将模式应用于八度矩阵,matrix,octave,Matrix,Octave,我在用八度音阶。我有一个随机的MxN矩阵。我想使用预定义模式将矩阵中的某些值设置为零: Matrix: Pattern: Result: [45 88 93 25 23 [1 0 [45 0 93 0 23 13 55 4 90 9 0 0] 0 0 0 0 0 34 87 67 07 88 34 0 67 0 9 13 57
Matrix: Pattern: Result:
[45 88 93 25 23 [1 0 [45 0 93 0 23
13 55 4 90 9 0 0] 0 0 0 0 0
34 87 67 07 88 34 0 67 0 9
13 57 14 16 27 0 0 0 0 0
94 35 68 22 89] 94 0 68 0 89]
如何才能做到这一点
谢谢 两种解决方案:
使用:
使用和从映像包:
pkg load image
ms = size(Matrix)
ps = size(Pattern)
col = im2col(Matrix,ps,'distinct'); % convert image to columns
colpat = col .* Pattern(:); % apply the pattern
result = col2im(colpat, ps,ms,'distinct'); % convert column back to image
所以模式矩阵应该在两个方向上重复?
pkg load image
ms = size(Matrix)
ps = size(Pattern)
col = im2col(Matrix,ps,'distinct'); % convert image to columns
colpat = col .* Pattern(:); % apply the pattern
result = col2im(colpat, ps,ms,'distinct'); % convert column back to image