Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a rectangular mask of 1's?

Status
Not open for further replies.

aushah

Electrical
Mar 7, 2014
1
Hi. I have a matrix of 768x1024. Now, within this matrix, I want to have a rectangle such that it is centered around the middle column of the matrix and has dimension (k)x1024, where k is a variable. This (k)x1024 rectangular portion within the 768x1024 matrix should have all entries 1 and the rest of the matrix entries should all be zero. So, it creates sort of a mask so that when I multiply it with another 768x1024 matrix, the result is only the rectangular part of the other matrix. All help is appreciated. Thanks.
ps: I am attaching a sketch of what I mean by what I said above.
 
Replies continue below

Recommended for you

poly2mask

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
Could you do it like this?
Code:
function main
totrow = 768;
totcol = 1024;  
k      = 10;    %Number of rows of ones
D      = maskmatrix(totrow,totcol,k)
end

function D = maskmatrix(totrow,totcol,k)
startones = floor((totrow-k)/2);
endones   = startones+k;

A = zeros(startones,totcol);
B = ones(k,totcol);
C = zeros(totrow-k-startones,totcol);
D = [A;B;C];
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor