Generate a sector mask within a big matrix
2 ビュー (過去 30 日間)
古いコメントを表示
A sector mask is defined by distance and angle. Please see the image for clarification on mask.
I want to generate a 100 by 100 matrix where all the matrix element inside the mask is 1 otherwise 0.

Thanks.
2 件のコメント
Looky
2019 年 12 月 11 日
Do you already have the coordinates as show in the image? Then just convert to polar using cart2pol and afterwards use some simple logic to check for radius and the angle.
採用された回答
Looky
2019 年 12 月 11 日
編集済み: Looky
2019 年 12 月 11 日
Solution could look like this:
% Generate example coordinates
x=linspace(-1,1,100);
y=fliplr(linspace(-1,1,100));
[X,Y]=meshgrid(x,y);
% Parameters for sector
angle=10;
radiusIn=.8;
radiusOut=.2;
% Coordinates to polarcoordinates
[phi, rho]=cart2pol(X,Y);
phi=rad2deg(phi);
phi(phi<0)=-phi(phi<0);
% Generate mask
mask=rho>radiusOut & rho<radiusIn & phi>angle& phi<180-angle;
% Have a look at the mask
spy(mask);
For your problem you should exchange the first part of generating the X and Y values for your own coordinates. Otherwise the mask might not be centered the way your data is.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!