MATLAB Answers

Rakesh V
0

how do I plot different 3D peaks in different locations in single polar plot

Asked by Rakesh V
on 15 Jul 2019
Latest activity Commented on by Star Strider
on 16 Jul 2019
In the image shown below I have a peak at center in polar plot. I need like that six peaks surrounding this main peak. Surrounding these six peaks I need nine peaks. To put it simply, in K shell I need 6 peaks, in L shell I need 9 peaks with central peak intact. I need them all in polar plot only.
thanks for help

  2 Comments

Please attach the jpg w/ the picture icon instead of as a paperclip download file...
peakcenter.jpgthis is polar plot, i need similar six peaks surrounding it in the same plot, but not as total subplots. Meaning the width of the main peak will be reduced. I donot want the peaks in the cartesian coordinates. i need them in polar plots. Even the equation would suffice. Or else even the plotting code also will help me. Thanks once again. feel free to ask more questions to get to clarity.

Sign in to comment.

1 Answer

Answer by Star Strider
on 15 Jul 2019
 Accepted Answer

Try this:
N = 500;
rv = linspace(0, 1, N); % Radius Vector
av = linspace(0, 2*pi, N); % Angle Vector
Ka = linspace(2*pi/12, 2*pi-2*pi/12, 6); % ‘K’ Angles
La = linspace(2*pi/18, 2*pi-2*pi/18, 9); % ‘L’ Angles
[R,A] = meshgrid(rv, av);
pkf = @(s) exp(-((((-15:15)).^2) + (((-15:15)).^2)')/s); % Creates Gaussian Peaks
Mf = @(M,r,c) M((-15:15)+r,(-15:15)+c); % Matrix Coordinates Grid For Each Peak
figure
[Xb,Yb,Zb] = pol2cart(A,R,zeros(size(R))); % Base Plane
surf(Xb,Yb,Zb)
hold on
surfc(Mf(Xb,16,16), Mf(Yb,16,16), pkf(50)*0.75) % Center Peak
for k = 1:numel(La) % ‘L’ Peaks
Rrow = 400;
ix = find(av <= La(k), 1, 'last');
[X(:,:,k),Y(:,:,k),Z(:,:,k)] = pol2cart(Mf(A,ix,Rrow),Mf(R,ix,Rrow),pkf(2)*0.25);
surf(X(:,:,k),Y(:,:,k),Z(:,:,k))
end
for k = 1:numel(Ka) % ‘K’ Peaks
Rrow = 200;
ix = find(av <= Ka(k), 1, 'last');
[X(:,:,k),Y(:,:,k),Z(:,:,k)] = pol2cart(Mf(A,ix,Rrow),Mf(R,ix,Rrow),pkf(5)*0.5);
surf(X(:,:,k),Y(:,:,k),Z(:,:,k))
end
hold off
shading interp
grid on
axis equal
view(-40,25)
producing:
how do I plot different 3D peaks in different locations in single polar plot - 2019 07 15.png
The grids are defined as (-15:15) for every peak and the coordinate arrays for them. If you change those dimensions, you will need to change them in both the ‘pkf’ and ‘Mf’ functions, as well as in the ‘Center Peak’ plot. The rest of the code should adapt automatically, although within limits.
Experiment to get the result you want.

  7 Comments

You did not say what problems you are having. You need to post the code you are using. What version (release) of MATLAB are you using? (My code was written in R2019a.)
I experimented with wider peaks, however that is likely not possible because of the constraints of the peak locations. The ‘s’ parameter of ‘pkf’ controls this to some extent, so you can experiment with that.
You can vary the peak amplitudes simply by multiplying them by whatever constant you want. One way to do that within the function iteslf is to add the amplitude as a parameter (here, ‘a’):
pkf = @(s,a) exp(-((((-15:15)).^2) + (((-15:15)).^2)')/s)*a; % Creates Gaussian Peaks
A slightly tweaked version of my earlier code that includes that function is:
N = 275;
rv = linspace(0, 1, N); % Radius Vector
av = linspace(0, 2*pi, N); % Angle Vector
Ka = linspace(2*pi/12, 2*pi-2*pi/12, 6); % ‘K’ Angles
La = linspace(2*pi/18, 2*pi-2*pi/18, 9); % ‘L’ Angles
[R,A] = meshgrid(rv, av);
pkf = @(s,a) exp(-((((-15:15)).^2) + (((-15:15)).^2)')/s)*a; % Creates Gaussian Peaks
Mf = @(M,r,c) M((-15:15)+r,(-15:15)+c); % Matrix Coordinates Grid For Each Peak
figure
[Xb,Yb,Zb] = pol2cart(A,R,zeros(size(R))); % Base Plane
mesh(Xb,Yb,Zb)
hold on
mesh(Mf(Xb,16,16), Mf(Yb,16,16), pkf(100,0.75)) % Center Peak
for k = 1:numel(La) % ‘L’ Peaks
Rrow = 150;
ix = find(av <= La(k), 1, 'last');
[X(:,:,k),Y(:,:,k),Z(:,:,k)] = pol2cart(Mf(A,ix,Rrow),Mf(R,ix,Rrow),pkf(50,0.25));
mesh(X(:,:,k),Y(:,:,k),Z(:,:,k))
end
for k = 1:numel(Ka) % ‘K’ Peaks
Rrow = 75;
ix = find(av <= Ka(k), 1, 'last');
[X(:,:,k),Y(:,:,k),Z(:,:,k)] = pol2cart(Mf(A,ix,Rrow),Mf(R,ix,Rrow),pkf(75,0.5));
mesh(X(:,:,k),Y(:,:,k),Z(:,:,k))
end
hold off
% shading interp
grid on
axis equal
view(-40,25)
producing:
how do I plot different 3D peaks in different locations in single polar plot (2) - 2019 07 15.png
This is the best I can do.
Rakesh V’s Answer moved here:
Dear SS,
I am using the same code which you have written to generate polar plot. I am using 2014b which our university provided us. That is the reason why i am unable to use the code.
The error was at this point.
pkf = @(s,a) exp(-((((-15:15)).^2) + (((-15:15)).^2)')/s)*a; % Creates Gaussian Peaks
If I remove the transpose in the above equation it executes.
hence i had the problem it seems.
Anyhow i will work it from here
Thanks and regards for the help.
My pleasure.
You did not descirbe the specific problems you are having. There may be ways to solve them if I know what they are.
My code works in 2019a, and does what you describe what you want it to do, following your original post.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.