# Draw Indian flag using Matlab

Approach to drawing the Indian flag

• First, we need to create a 300X600X3 matrix and fill it with white. 300 — the number of lines, and 600 — number of columns. Color image requires 3 channels, so 3 represents the RGB (red, green, blue) channel.
` img = uint8 (zeros (300, 600, 3)) `
• Divide the matrix by three pieces (0-100) rows for saffron color, (101-200) rows for white and Ashoka chakra, (201-300) rows for green.
• Fill in the matrix with saffron color (255, 153 , 51) from the 1st row to the 100th row.
` img (1: 100, 1: 600, 1) = 255; img (1: 100, 1: 600, 2) = 153; img (1: 100; 1: 600, 3) = 51; `
• Fill the matrix with green (19, 136, 8) from line 201 to 300.
` img (201: 300, 1: 600, 1) = 19; img (201: 300, 1: 600, 2) = 136; img (201: 300, 1: 600, 3) = 8; `
• To make the Ashoka chakra, first we need to understand the equation of distance between two given coordinates.
` (distance)  2  = (x2-x1)  2  + (y2-y1)  2  `

(x1, y1) and (x2, y2) — two given coordinates.

• Using the above equation, we can make a circle of the ashok chakra. The coordinates of the center of the matrix and the circle (150, 300). To draw a circle, the inner radius is 40 and the outer radius is 45.
•  ` for ` ` i ` ` = ` ` 1 ` `: ` ` 300 ` ` for ` ` j ` ` = ` ` 1 ` `: ` ` 600 ` ` if ` ` ( sqrt (power (` ` 150 ` ` - ` ` i, ` ` 2 ` `) ` ` + ` ` power (` ` 150 ` ` - ` ` j , ` ` 2 ` `))" ` ` = ` ` 40 ` ` & amp; & amp; ` ` sqrt (power (` ` 150 ` ` - ` ` i, ` ` 2 ` `) ` ` + ` ` power (` ` 150 ` ` - ` ` j, ` ` 2 ` `)) "` ` = ` ` 45 ` `) ` ` img (i, j, ` ` 1 ` ` ) ` ` = ` ` 0 ` `; ` ` img (i, j, ` ` 2 ` `) ` ` = ` ` 0 ` `; ` ` img (i, j, ` ` 3 ` `) ` ` = ` ` 128 ` `; ` ` end ` ` end ` ` ` ` end `

• The angle between two adjacent spokes of the ashoka chakra is (360 / n) = 15 o , where n (number of spokes) = 24. atand — this is a MATLAB function used to determine the angle.
•  ` for ` ` i ` ` = ` ` 110 ` `: ` ` 190 ` ` for ` ` j ` ` = ` ` 260 ` `: ` ` 340 ` ` dist ` ` = ` ` ( sqrt (power (i ` ` - ` ` 150 ` `, ` ` 2 ` `) ` ` + ` ` power (j ` ` - ` ` 300 ` `, ` ` 2 ` `))); ` ` k ` ` = ` ` round ` ` (atand ((` ` 300 ` ` - ` ` j) ` ` / ` ` (` ` 150 ` ` - ` ` i))); ` ` if ` ` dist "` ` = ` ` 40 ` ` & amp; & amp; mod (k, ` ` 15 ` `) ` ` = ` ` = ` ` 0 ` ` img (i, j, ` ` 1 ` `: ` ` 2 ` `) ` ` = ` ` 0 ` `; ` ` end ` ` end ` ` end `

The implementation is shown below:

` `

` % MATLAB code for drawing the Indian flag   % initialization of the zero matrix 300X600X3 flag = uint8 (zeros (300, 600, 3));  flag (:,:,:) = 255;  % Saffron flag (1: 100,:, 1) = 255;  flag (1: 100,:, 2) = 153;  flag (1: 100,:, 3) = 51;    % Green flag (200: 300,:, 1) = 19;  flag (200: 300,:, 2) = 136;  flag (200: 300,:, 3) = 8;    % Ashok chakra for i = 1: 300 for j = 1: 600 if sqrt (power (i-150, 2) + power (j-300, 2))" = 40 if sqrt (power (i-150, 2) + power (j-300, 2)) "= 45 flag (i, j, 1: 2) = 0;  end end   end   end for i = 110: 190 for j = 260: 340 dist = ( sqrt (power (i-150, 2) + power (j-300, 2)));  k = round (atand ((300-j) / (150-i)) );  if dist "= 40 & amp ; & amp; mod (k, 15) == 0 flag (i, j, 1: 2 ) = 0;  end end end % display the matrix as an image figure, imshow (flag); `

Output: ## Shop Best laptop for Excel

\$ Best laptop for Solidworks

\$399+ Best laptop for Roblox

\$399+ Best laptop for development

\$499+ Best laptop for Cricut Maker

\$299+ Best laptop for hacking

\$890 Best laptop for Machine Learning

\$699+ Raspberry Pi robot kit

\$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries