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

Write a MATLAB program in a script file that asks the user to input a matrix of

ID: 3839915 • Letter: W

Question

Write a MATLAB program in a script file that asks the user to input a matrix of any arbitrary size. Then the program must use nested for loops to examine each element of the matrix. If the element is positive its value is doubled. If the element is negative its value is tripled. The value of zero can be done in each way (it is not altered). The program displays the matrix that was entered and the modified matrix as well. Use the program with the following matrices: 0 13 -8 -6 -2 -8 -1 -9 8 1 4 3 -7 10 1 -12 -9 -9 -7 -15 0 -2 8 -2 -15 7 14 -14 -17 -13 -2 2 3 6 -18 -14 -8 9 -18 -9

Explanation / Answer


r=input('enter how many rows :')
c=input('enter how many columns :')
in=[]
out=[]
for i=1:r
for j=1:c
in(i,j)=input('element :')
end
end
for i=1:r
for j=1:c
if(in(i,j)>0)
out(i,j)=2*in(i,j)
elseif(in(i,j)<0)
out(i,j)=3*in(i,j)
else
out(i,j)=in(i,j)
end
end
end

disp(in)
disp(out)

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