How to build a circularly symmetric matrix from a vector

11 views (last 30 days)
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 Comment
Eugene Kim
Eugene Kim on 26 Oct 2022
Did you ever find a solution to this? I am currently trying to do something very similar.

Sign in to comment.

Answers (3)

Matt J
Matt J on 26 Oct 2022
Edited: Matt J on 26 Oct 2022
x=discretize(1:100,5); %hypothetical input
plot(x); axis padded
a=normalize(1:2*numel(x)-1 , 'center');
[~,R]=cart2pol(a,a');
Image=interp1(x,R+1,'linear',0);
imshow(Image,[]); colorbar

David Hill
David Hill on 26 Oct 2022
Edited: David Hill on 26 Oct 2022
[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 Comment
Eugene Kim
Eugene Kim on 27 Oct 2022
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!

Sign in to comment.


DGM
DGM on 27 Oct 2022
Edited: DGM on 27 Oct 2022
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 Comments
DGM
DGM on 27 Oct 2022
Edited: DGM on 27 Oct 2022
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
Eugene Kim on 27 Oct 2022
Edited: Eugene Kim on 27 Oct 2022
@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!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!