×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources