Re: [問題] 如何在矩陣中沿某角度取值?

看板MATLAB作者 (Jeff)時間7年前 (2016/10/10 02:52), 7年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 107.3.161.162 ※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1476039122.A.1C9.html ※ 編輯: Jeffch (107.3.161.162), 10/10/2016 02:52:51
文章代碼(AID): #1N-f7I79 (MATLAB)
文章代碼(AID): #1N-f7I79 (MATLAB)