How to build a circularly symmetric matrix from a vector
5 次查看(过去 30 天)
显示 更早的评论
Hi,
If I want a matrix, like one used to generate the figure below:

but all I have is a vector (any diameter), please how can I build the matrix from the vector? Like spinning the 1 x n vector about its center to generate an n x n matrix.
Another example: if I want to build something like this
0.00 0.00 0.00 10.00 0.00 0.00 0.00
0.00 7.78 1.11 -1.11 1.11 7.78 0.00
0.00 1.11 -5.56 -7.78 -5.56 1.11 0.00
10.00 -1.11 -7.78-10.00 -7.78 -1.11 10.00
0.00 1.11 -5.56 -7.78 -5.56 1.11 0.00
0.00 7.78 1.11 -1.11 1.11 7.78 0.00
0.00 0.00 0.00 10.00 0.00 0.00 0.00
from this vector, or a polynomial that describes the vector.
10.00 -1.11 -7.78-10.00 -7.78 -1.11 10.00
Thanks a lot in advance!
1 个评论
Eugene Kim
2022-10-26
Did you ever find a solution to this? I am currently trying to do something very similar.
回答(3 个)
David Hill
2022-10-26
编辑:David Hill
2022-10-26
[x,y]=meshgrid(0:.05:100);
z=sqrt((x-50).^2+(y-50).^2);
Z=(z-25)/25;
Z(z>50)=nan;
contour(x,y,Z,'FaceColor','flat')
colormap jet
shading interp
1 个评论
Eugene Kim
2022-10-27
I have tried both of the methods posted here, but it is not working with my particular set of data.
Here is what I tried, and it gets close to what I want but isn't quite there.
I have a vector X which is a single row vector containing a series of logarithmically increasing values from 0 to 1 and back to 0, such that it is symmetrical around zero. numel(X) = 41. Vector Y is just = X' .
Here is the code I used to generate these vectors.
spread = logspace(0,-.7,20);
xb = 10 - 10.*spread;
xvec = [10 flip(xb,2) xb(2:end) 10];
yvec = xvec';
kernel = exp(-(bsxfun(@plus,xvec,yvec)));
surf(kernel);

The issue is that I would like to get this kernel to be circular such that the probability density is rotationally symmetric.
But I'm not sure how I need to feed my data into the above solutions to get it to output what I want.
Thanks for the help!
DGM
2022-10-27
编辑:DGM
2022-10-27
Depends on what exactly you're expecting.
w = 20; % filter half-width
% some arbitrary profile
spread = logspace(0,-0.7,w);
xb = [(10 - 10.*spread) 10];
% function is rotationally symmetric
% so it's a function of R
x = -w:w;
y = x.';
R = sqrt(x.^2 + y.^2);
% interpolate
fk = interp1(0:w,xb,R,'linear',10);
fk = exp(-fk);
surf(fk);
Note that R<=w only in an inscribed circular region. In the corners, R>w, so you'd need to extrapolate. By default, interp1() will fill those regions with NaN. Since you're manually pinning the outer values to 10, I figured it'd suffice to set those extrapolated regions to 10. If you want the tails of the profile to extend fully into the corners, you'd need your profile to be defined over w*sqrt(2).
EDIT: if you're using R2016a or older, you'll have to use bsxfun() when calculating R.
4 个评论
DGM
2022-10-27
编辑:DGM
2022-10-27
FWIW, I didn't notice that both the prior answers were new. The way I saw it, the prior answers addressed the general question from 2016, and that there was a new question-as-comment seeking specific help. I didn't realize the order of events here. I kind of have a habit of answering dead questions, so it seemed totally normal to me.
Eugene Kim
2022-10-27
编辑:Eugene Kim
2022-10-27
@Matt J Sorry, I should have mentioned that the solution shown on this page was missing a function you use (ndgrid), but the message that was sent to my email did contain that line.. very strange. Anyway, I tried your solution and it also worked!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



