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

Write a MATLAB program to create a SINGLE MATRIX of characters as shown below. T

ID: 2291210 • Letter: W

Question

Write a MATLAB program to create a SINGLE MATRIX of characters as shown below. The generated matrix MUST include a single space character for columns 2 and 6 1 ABC DEF 2 ABC DEF 3 ABC DEF 4 ABC DEF 5 ABC DEF 6 ABC DEF 7 ABC DEF Your program MUST perform the FOLLOWING TASKS 1. Generate the SINGLE MATRIX with exactly the same format as shown above 2. Prompt the user to input an integer number (num) within the range 1šnums15 3. Your program MUST verify if the inputted number num is an integer and within the specified range. If not, your program MUST display a message on the screen stating that the number entered was incorrect and allow the user to re-enter the number without the need to rerun the program 4. You MUST use the random number generation function(s) from Matlab, to generate automatically num random and distinct element positions in the matrix and substitute each of them by the letter X' only for the columns corresponding to the characters ?', 'B', 'C', 'D', ?', or . Your program MUST display the modified matrix on the screen. Your program MUST also check and eliminate duplicated random selections. The examples below show the original matrix and the modified matrix when num-5 and num-10 were inputted. Original Matrix 1 ABC DEF 2 ABC DEF 3 ABC DEF 4 ABC DEF 5 ABC DEF 6 ABC DEF 7 ABC DEF Modified Matrix: num-5 1 ABC DEX 2 ABC DEF 3 ABC DEF 4 XXC DEF 5 ABC DEF 6 ABC DXF 7 ABC XEF Modified Matrix: num=10 AXC DXF 2 XBC DXF 3 ABC DEF 4 ABC DEF 6 ABC XEX 7 ABC XEF 5. Your program MUST allow the user to repeat the procedure without the need to rerun the program

Explanation / Answer

input code

clear;
clc;
i=1; %variable for repeat entair process once more
while i==1 %while i=1 do the process
%generating the matrix
singlematrix=['1',' ','A','B','C',' ','D','E','F';
'2',' ','A','B','C',' ','D','E','F';
'3',' ','A','B','C',' ','D','E','F';
'4',' ','A','B','C',' ','D','E','F';
'5',' ','A','B','C',' ','D','E','F';
'6',' ','A','B','C',' ','D','E','F';
'7',' ','A','B','C',' ','D','E','F'];
disp(singlematrix); %display the generated matrix
prompt='Enter a number between 1 and 15: ';
num=input(prompt); %ask the user to enter num value from 1 to 15
while ~(num>=1&&num<=15) %checking the num is between 0 and 15
prompt='Number entered is incurrect please enter a number between 1 and 15: ';
num=input(prompt); %if not ask to re enter
end

for k=1:num %for mum number of entries for substitute X
i=randi(7); %random number for row index
j=randi(9); %random number for column index
while j==1||j==2||j==6 %check the column number not equl to 1 or 2 or 6
j=randi(9); %if yes re generate the number
end
if singlematrix(i,j)=='X' %check i,j positions already substitute with x
k=k-1; %if yes reduce the number of entries
end
singlematrix(i,j)='X'; %i,j positions substitute with x
end
prompt2="Modified matrix is: ";
disp(prompt2);
disp(singlematrix); %print modified matrix
prompt3='enter 1 to repeat process or 0 to abort: ';
i=input(prompt3); %read i value for repeat the process or not
end

output

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