How to create a 2D circular intensity plot?

7 Ansichten (letzte 30 Tage)
Zeba
Zeba am 18 Dez. 2014
Kommentiert: MatlabUser am 18 Feb. 2022
Hi, I can generate 2D plots like in the image above in comsol. I want to generate the same in matlab. This is a plot of electric field distribution in a cylindrical resonator. My matlab code has the electric field as a function of radius and angle. May be creating a meshgrid and then using polar command might be the way to go but I am not sure how to do that correctly. Any suggestion or link would be appreciated. Thanks </matlabcentral/answers/uploaded_files/22752/snapshot.png>

Antworten (2)

Thorsten
Thorsten am 18 Dez. 2014
Bearbeitet: Thorsten am 18 Dez. 2014
Define your X Y Cartesian coordinates with meshgrid, convert to radius and angle
R = sqrt(X^2 + Y^2);
A = atan2(Y, X);
and run your function on R and A.

Zeba
Zeba am 19 Dez. 2014
Thanks for your reply! I am sorry, I meant Electric field values are calculated and stored in a matrix. So I know what's the field at a given radius and angle. I used the following snippet to make it work axes(handles.axes2)
[rr, tt]=meshgrid(linspace(0,2*r(1),length(y)), linspace(0,2*pi,length(y)));
xx=rr.*cos(tt);
yy=rr.*sin(tt);
hh=polar(xx,yy);
zz=(repmat(y,length(y),1).*cos(m*tt)).^2;
hold on; pcolor(xx,yy,zz); shading interp; set(hh,'visible', 'off');
axis off
axis image I had found part of it on some webpage while searching for help. When I try to change the colorbar range, I get an error Error using set
Bad property value found.
Object Name: axes
Property Name: 'CLim'
Values must be increasing and non-NaN.
The code for the up and down pushbuttons in the figure below is
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
color_range=get(handles.axes2,'Clim');
newcolor_range=[color_range(1)*2 0];
set(handles.axes2,'Clim',newcolor_range)
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
color_range=get(handles.axes2,'Clim');
newcolor_range=[color_range(1)/2 0];
set(handles.axes2,'Clim',newcolor_range)
How do I get rid of this error while changing colorbar range? It works with normal axes. Thanks
  4 Kommentare
Thorsten
Thorsten am 20 Dez. 2014
Please formally accept my answer if it was helpful.
MatlabUser
MatlabUser am 18 Feb. 2022
can you please share the working code with intensity input thing?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by