Re: [问题] 如何在矩阵中沿某角度取值?

楼主: Jeffch (Jeff)   2016-10-10 02:51:59
※ 引述《oo2751394 (蒜泥白肉)》之铭言:
: 不好意思
: 小弟菜鸟
: 例如一个矩阵[1,2,3;4,5,6;7,8,9];
: 以(2,2)为中心,0度就是4,5,6
: 改成+45度就是3,5,7
: 像是这样的概念
: 想问有没有办法像上面讲的描述?
: (我的资料很大QQ快爆了)
function L = arbitary_slice(Z)
%% Step 1. Rotate matrix
X = meshgrid(1:m); % m is better to be an odd number
Y = meshgrid(1:m);
Z = Z(1:m,1:m);
X = reshape(X,1,[]);
Y = reshape(Y',1,[]);
Z = reshape(Z,1,[]);
[rotX; rotY; Z] = Rz(theta)*[X; Y; Z];
% Rz is the rotation matrix along Z.
% https://en.wikipedia.org/wiki/Rotation_matrix
%% Step 2. Digitize the rotated matrix (or resampling) to the new meshgrid
newX = meshgrid(1:n) % n is better to be an odd number
newY = meshgrid(1:n)'
% obtain newZ(1:n,1:n) by pojecting Z(rotX,rotY) to newZ(newX,newY)
%% Step 3. Take a slice
L = newZ(:,(n-1)/2);
end

Links booklink

Contact Us: admin [ a t ] ucptt.com