How to create a 2D circular intensity plot?

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>

回答(2 个)

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 2014-12-19
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 个评论

This is a new question. Please accept my answer and start a new question with a new title that better reflects your current problem.
I figured out the problem. Thanks
Please formally accept my answer if it was helpful.
can you please share the working code with intensity input thing?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

提问:

2014-12-18

评论:

2022-2-18

Community Treasure Hunt

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

Start Hunting!

Translated by