Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Only by using matlab and don not use hard codes and try to use aome of these functions: (For, while, if, rand, round, floor, print,
Only by using matlab and don not use hard codes and try to use aome of these functions: (For, while, if, rand, round, floor, print, input, etc..), they should be understanded and explained
QUESTION You are asked to write program files (a main file and four function files ) that print a geometric shape on the command window, and also visualize the same shape by using "imagesc()" built-in function, with the entered specifications. The program will ask the user for following parameters; The type of geometric shape (a triangle, a square, a rectangle or a circle). The dimensions of the entered geometric shape (the height for the triangle, a side of rectangle, the radius of the circle and etc.) The type of character which would be used in printing the geometric shape on command window. The program will be run by using the main HW1.m file and then this main .m file will call one of four user defined functions that would be written by you. These functions will be named as below; print_triangle() print_rectangle() print_square print_circle The input parameters and how these parameters would be passed into functions are described in the main HW1.m file as given below. As you may notice, the printed shapes on the command window do not represent exact visual sense for the chosen geometric shape. For example, when the user selects a circle as his/her geometric shape, the printed shape does not seem like a perfect circle. This situation is also seen in other geometric shapes. The reason for this unwanted behavior occurs due to the inconsistency occurring in the space widths between the consecutive characters and lines. In order to come over this drawback in the visualization of your geometric shapes, a better option would be using the imagesc()" built-in function of the Matlab. By using the imagesc() function, the content of the matrices can be visualized with respect to the values of each member. To be able to use the "imagesc() function and print the chosen geometric shape on command window, you will apply the following steps; you will define a background matrix having the dimension of 21x21. The default value of each member would be zero. you will fill the relevant locations (the members of background matrix that must be located inside the shape boundary) with value of one (1) to be able to represent the chosen shape. you will use the processed matrix to print the chosen shape in command window and also to visualize the shape by using "imagesc()". the center points (centroid) of the chosen images must be located in the middle (11,11) of the background matrix. An exact match is not necessary but the chosen image must be centered to the 21x21 background matrix for both command-window output and imagesc() output. in the command-window output, the members of the background matrice having O value will be printed as ' (space character) while the members that are l would be printed in the form of user input. Specifications for the code are given below. Program should have the main file code given below (also shared as an m-file) that requests the shape choice from the user. Each shape requests two inputs. First input is the required shape size parameters as integers in terms of the character count, second is the character type to be printed. o Shape parameters are; Triangle: Height (i.e. number of rows) Rectangle: Side lengths (height and width) as a vector Square: Side length Circle: Radius Each shape then should call its own function to calculate the positions to print the characters, and print the chosen shape on the command window, and also visualize it by using imagesc()" built- in Matlab function. You may get bonus points for adding checks for input limitations and/or area limitations checks such that each printing an error and requesting new inputs. You should write a report on your work using the supplied report format. You should be expressive and unique on your explanations and comments. . Main File Code clc,clear all,close all choice = input('Please enter your choice 1 for Triangle, 2 for Rectangle, 3 for Square, 4 for Circle = '); while(1) if -((choice == 1) || (choice == 2) || (choice == 3) || (choice == 4)) fprintf("You made a wrong choice, please try again ') choice = input('Please enter your choice 1 for Triangle, 2 for Rectangle, 3 for square, 4 for Circle = '); else break; end end switch choice case 1 triangle_height = input('Please enter the height of the triangle: '); printed char=input('Please enter the char type that you want to print: '); print_triangle(triangle_height, printed_char); case 2 rectangle_parameters = input('Please enter the height and width of the rectangle: '); printed_char =input('Please enter the char type that you want to print: '); print_rectangle(rectangle_parameters, printed_char); case 3 square_side = input('Please enter the side width of the square: '); printed_char =input('Please enter the char type that you want to print: '); print_square(square_side, printed_char) case 4 circle_radius=input('Please enter the radius of the circle: '); printed_char =input('Please enter the char type that you want to print: '); print_circle(circle_radius, printed_char) endStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started