[英]Generalize this matlab code for non-square matrices
我正在matlab中研究一些傅立葉變換代碼,遇到了以下問題:
xx = meshgrid(1:N);
% Center on DC
xx = xx - dcN;
% normalize dynamic range from -1 to 1
xx = xx./max(abs(xx(:)));
% form y coordinate from negative transpose of x coordinate (maintains symmetry about DC)
yy = -xx';
% compute the related radius of the x/y coordinates centered on DC
rr = sqrt(xx.^2 + yy.^2);
如何針對非平方矩陣對此進行概括? 該代碼假設我的矩陣是正方形,因此dcN是正方形矩陣的中心(換句話說,對於11x11,dcN = 6)。
當對非方陣進行轉置時,數學無法解決該yy變量。
我試圖弄清楚我是否可以使網格從“上到下”而不是從左到右-但我也無法弄清楚。
謝謝
我試圖弄清楚我是否可以使網格從“上到下”而不是從左到右-但我也無法弄清楚。
>> N=5
N =
5
>> rot90(meshgrid(N:-1:1))
ans =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
根據您的問題,我想您想找到rr
,即矩陣中任何元素到中心的距離。
如果您想要一個M×N陣列,請執行以下操作
%# note that using meshgrid instead of ndgrid will swap xx and yy
[xx,yy] = ndgrid(-(M-1)/2:(M-1)/2,-(N-1)/2:(N-1)/2);
%# normalize to the max of xx,yy
nrm = max((M-1)/2,(N-1)/2);
xx = xx./nrm;
yy = yy./nrm;
rr = sqrt(xx.^2+yy.^2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.