Info

此问题已关闭。 请重新打开它进行编辑或回答。

Create matrix of rectangular ones

2 次查看(过去 30 天)
LM
LM 2021-7-1
关闭: Stephen23 2021-7-1
I wrote a script that creates a 248x286 matrix of zeros with rectangular verticle bars of varying widths and element values 255. I would like to make 9 rectangular bars in the north, south, east, west and center locations. The script works for one set of bars but it is not well-written. I would appreciate help to optimize my program below. Thank you.
A = zeros(248,286); %create matrix of zeros
A(20:60,124:134) = 1 %north: rectangles 40 pixels long and 10 pixels wide
A(20:60,144:154) = 1
A(20:60,164:174) = 1
A(70:120,124:130) = 1 %north: rectangles 40 pixels long and 6 pixels wide
A(70:120,140:146) = 1
A(70:120,156:160) = 1
A(130:170,124:126) = 1 %north: rectangles 40 pixels long and 2 pixels wide
A(130:170,136:138) = 1
A(130:170,148:150) = 1
m = A*255;
imshow(m)
imwrite(m, 'Verticle_bars.bmp')

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by