# I would like to make a rectangle, x goes from 0 to o.1, 0.2, 0,3....etc and fill the rectangle with different colors? what is the best possible approach for this ? thank you

1 Ansicht (letzte 30 Tage)
Kommentiert: Geoff Hayes am 18 Mär. 2022
I would like to make a rectangle, x goes from 0 to o.1, 0.2, 0,3....etc and fill the rectangle with different colors? what is the best possible approach for this ? , x represents a depth and at each depth I should asgin adifferent color. Please see example attached. Thank you.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Geoff Hayes am 18 Mär. 2022
@Zahir Elharith Mohammedelamein Ahmed - consider using rectangle to create multiple rectangles side-by-side. You can set the colour for each. For example,
rectangle('Position',[0,0,5,1],'FaceColor','b');
rectangle('Position',[5,0,3,1],'FaceColor', [0.5 0.5 0.1]);
xlim([-2 10])
ylim([-5 5])
The above code creates two rectangles of the same height but different lengths and colours.
##### 2 KommentareKeine anzeigenKeine ausblenden
Thank you very much. one more thing I forgot to mention is: what should I do if I want to make a for loop sayin if the number was (1) for example the rectangle should be colored blue...and so on..
Geoff Hayes am 18 Mär. 2022
You could try something like
myNumber = 1;
rectColor = '';
if myNumber == 1
rectColor = 'b';
end
rectangle('Position',[0,0,5,1],'FaceColor', rectColor);

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by