Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2) Write a MATLAB script that will build a triangle of symbols. This pro

ID: 3602010 • Letter: P

Question

Problem 2) Write a MATLAB script that will build a triangle of symbols. This program should allow for the user to specity the symbol to use, and should accept any character or string value. It should also enable the user to select the height of the triangle built. Finally, the program should enforce the user to only use a single character as the symbol. An example of the execution and output is below. Specify a character to print in your loop: Tx How tall would you like your image? 4 Please input only a single character: Ty Please input only a single character: T Note -it is possible to do this with either for or while loops, but you will need a loop inside of a loop. https://iu.instructure.com courses/1 664789/assignments/7664878#submit

Explanation / Answer

% Taking user input
letter = input("Specify a characater to print in your loop: ",'s');
n = input("How tall would you like your image? ");

while numel(letter)!=1
letter = input("Please input only a single character: ",'s');
end

% looping for n times
for i = 1:n
% looping for i times and concatenating characters to line and printing it
line = "";
for j = 1: i
line = strcat(line,letter);
end
disp(line)
end

SAMPLE OUTPUT

Specify a characater to print in your loop: Tx
How tall would you like your image? 4
Please input only a single character: Ty
Please input only a single character: T
T
TT
TTT
TTTT

% Taking user input
letter = input("Specify a characater to print in your loop: ",'s');
n = input("How tall would you like your image? ");

while numel(letter)!=1
letter = input("Please input only a single character: ",'s');
end

% looping for n times
for i = 1:n
% looping for i times and concatenating characters to line and printing it
line = "";
for j = 1: i
line = strcat(line,letter);
end
disp(line)
end

SAMPLE OUTPUT

Specify a characater to print in your loop: Tx
How tall would you like your image? 4
Please input only a single character: Ty
Please input only a single character: T
T
TT
TTT
TTTT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote