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