将此 matlab 代码推广到非方阵
我正在 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 变量的数学运算不起作用。
我试图弄清楚是否可以制作一个从“上到下”而不是从左到右的网格 - 但我也无法弄清楚。
谢谢
I am working on some fourier transform code in matlab, and have come across the following:
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);
How can I generalize this for non-square matrices? This code is assuming my matrix is square, so dcN is the center of the square matrix (in other words, with 11x11, dcN = 6).
The math doesnt work out for that yy variable when the transpose is taken for a non-square matrix.
I have tried to figure out if I can make a meshgrid going from "top to bottom" instead of left to right - but I havent been able to figure taht out either.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从你的问题来看,我猜你想找到 rr,即矩阵中任何元素距中心的距离。
如果您希望将其用于 M×N 数组,您可以执行以下操作
From your question I guess that you want to find
rr
, i.e. the distance of any element in the matrix from the center.If you want this for a M-by-N array, you'd do the following