How to create a ring using meshgrid with user defined radius ?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I want to make a ring using meshgrid with user defined radius. Thanks
採用された回答
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 件のコメント
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
2016 年 9 月 28 日
How you can get one output for a 2D problem? As the ring is 2D, you will have two coordinates which specify the location.
I mean, I need one 2D matrix as an image in the output
KSSV
2016 年 9 月 29 日
You will get 2D matrices for x and y.
Can I get only one 2D matrix ?
KSSV
2016 年 9 月 29 日
Yes one 2D matrix for x and one 2D matrix for y.
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 ?
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?
Thanks it is perfect
KSSV
2016 年 10 月 3 日
I am curious to know...why you are specific about single output?
I have 3D data and I want to correlate the 2D ring matrix with each slice of 3D data.
その他の回答 (1 件)
Image Analyst
2016 年 10 月 3 日
カテゴリ
ヘルプ センター および File Exchange で Lighting, Transparency, and Shading についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
