How to create a ring using meshgrid with user defined radius ?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I want to make a ring using meshgrid with user defined radius. Thanks
Accepted Answer
clc; clear all ;
M = 10 ;
N = 100 ;
R1 = 0.5 ; % inner radius
R2 = 1 ; % outer radius
nR = linspace(R1,R2,M) ;
nT = linspace(0,2*pi,N) ;
%nT = pi/180*(0:NT:theta) ;
[R, T] = meshgrid(nR,nT) ;
% Convert grid to cartesian coordintes
X = R.*cos(T);
Y = R.*sin(T);
[m,n]=size(X);
% Plot grid
figure
set(gcf,'color','w') ;
axis equal
axis off
box on
hold on
% Plot internal grid lines
for i=1:m
plot(X(i,:),Y(i,:),'k','linewidth',1.5);
end
for j=1:n
plot(X(:,j),Y(:,j),'k','linewidth',1.5);
end
You may check the link:
11 Comments
Israr Ul Haq
on 28 Sep 2016
Dr. Siva Srinivas Kolukula, Thanks for your answer. Is it possible to get one output variable, which contains the ring ? Because here you are plotting X and Y separately.
KSSV
on 28 Sep 2016
How you can get one output for a 2D problem? As the ring is 2D, you will have two coordinates which specify the location.
Israr Ul Haq
on 29 Sep 2016
I mean, I need one 2D matrix as an image in the output
KSSV
on 29 Sep 2016
You will get 2D matrices for x and y.
Israr Ul Haq
on 29 Sep 2016
Can I get only one 2D matrix ?
KSSV
on 29 Sep 2016
Yes one 2D matrix for x and one 2D matrix for y.
Israr Ul Haq
on 29 Sep 2016
K0 =[0 1] [x,y,z] = meshgrid(-A/2:(A/2)-1,-D/2:(D/2)-1,-B/2:(B/2)-1); out = exp( 1i * (k0(1) * x + k0(2) * y + k0(3)*z));
In this case the output is only one 3D matrix that is "out". I need just one output matrix like this.
"Yes one 2D matrix for x and one 2D matrix for y" it means there are 2 images that is x and y, but I only need one image as a ring. can we combine x and y to make only one matrix ?
KSSV
on 3 Oct 2016
clc; clear all ;
N = 100 ;
R1 = 0.5 ; % inner radius
R2 = 1 ; % outer radius
th = linspace(0,2*pi,N) ;
% inner circle
x1 = R1*cos(th) ; y1 = R1*sin(th) ;
% Outer circle
x2 = R2*cos(th) ; y2 = R2*sin(th) ;
% merge both
x = [x1 NaN fliplr(x2)] ;
y = [y1 NaN fliplr(y2)] ;
%%Make a mesh
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
xx = linspace(x0,x1,N) ;
yy = linspace(y0,y1,N) ;
[X,Y] = meshgrid(xx,yy) ;
%%Get points inside the ring
D = (X.^2+Y.^2) ;
D(D<R1) = NaN ;
D(D>R2) = NaN ;
pcolor(D) ;
shading interp ;
D will be a single matrix. Is it okay?
Israr Ul Haq
on 3 Oct 2016
Thanks it is perfect
KSSV
on 3 Oct 2016
I am curious to know...why you are specific about single output?
Israr Ul Haq
on 4 Oct 2016
I have 3D data and I want to correlate the 2D ring matrix with each slice of 3D data.
More Answers (1)
Image Analyst
on 3 Oct 2016
0 votes
Categories
Find more on Polygons in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)