Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Create matrix of rectangular ones

2 Ansichten (letzte 30 Tage)
LM
LM am 1 Jul. 2021
Geschlossen: Stephen23 am 1 Jul. 2021
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')

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by