Generate a sector mask within a big matrix

조회 수: 2 (최근 30일)
Ankit Labh
Ankit Labh 2019년 12월 11일
댓글: Ankit Labh 2019년 12월 11일
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.
MASK.png
Thanks.
  댓글 수: 2
Looky
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.
Turlough Hughes
Turlough Hughes 2019년 12월 11일
Can you attach the matrix as a .mat

댓글을 달려면 로그인하십시오.

채택된 답변

Looky
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.
  댓글 수: 1
Ankit Labh
Ankit Labh 2019년 12월 11일
Dear Looky,
Many thanks for your answer. It worked. I got many new ideas for other questions.
best regards,
Ankit

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by