Change language

# How to draw the Japan flag using MATLAB

| | |

MATLAB, also called Matrix Laboratory, is a computing environment and platform for programming languages. It was designed and developed by MathWorks. MATLAB — it is a framework that allows us to perform matrix manipulations, implement algorithms, display functions and data, create user interfaces and interact with programs written in different programming languages ​​such as C, C++, Python, Java, etc.

How to draw a color image in MATLAB?
A color image can be represented as a 3-order matrix. The first order is for rows, the second order is for columns, and the third order is for specifying the color of the corresponding pixel. We are using RGB color format here, so the third order will take 3 values ​​Red, Green and Blue, respectively. The row and column values ​​depend on the size of the image.

Approach to draw the flag of Japan:

• Create an order 3 zero matrix measuring (300 , 500, 3), where 300 is the number of pixels for rows, 600 is the number of rows, and 3 is RGB color coding.
• First color the entire matrix white. RGB for red (255, 255, 255).
` I (:,:,:) = 255; `
• Loop over rows and columns and implement the equation of the circle so that we got the circle in the center of the flag and colored it in crimson glory using RGB format.
Circle equation:
` ((xh) ^ 2 - (yk) ^ 2) = r ^ 2 `

where (h, k) & # 8212 ; centers, (x, y) — the x-axis and y-axis coordinates and the radius of the circle.
RGB format for crimson glory color (188, 0, 45).

Below is the code:

 `% create a 2-D matrix and paint it white ` ` I = uint8 (zeros (300, 500, 3)) + 255; `   `% center 1 through which the circle will pass ` ` circle_center1 = 150; `   `% of the center point 2 that the circle will pass through ` ` circle_center2 = 250; `   ` radius = 6.32; ` `% circle radius ` ` x = i; ` `% X-axis ` ` y = j; ` `% y-coordinate `   `% loops for strings, ie for the X axis ` ` ` ` for ` ` i = 101: 200 `   `% column loops, i.e. for Y-axis ` ` for ` ` j = 101: 300 `   `% apply the circle equation to make a circle in the center. ` ` if ` ` round ( sqrt ((i-circle_center1) ^ 2 + (j-circle_center2) ^ 2)) & lt; radius ^ 2 `   `% fill the circle with crimson glory ` `% color using RGB color representation. ` ` I (i, j, 1) = 188; ` ` I (i, j, 2) = 0; ` ` I (i, j, 3) = 45; `   ` end `  ` `  ` ` ` end ` `% end of column loop. ` ` end ` `% end of line loop. `   `% show the rendered image. ` ` figure, imshow (I); `

Output:

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

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

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

NUMPYNUMPY

glob exclude pattern

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

NUMPYNUMPY

Python CSV error: line contains NULL byte

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

## 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