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

T-Mobile * 34%) 12:33 AM libproxy.library.unt.edu initialized): newr %Note this/

ID: 3601740 • Letter: T

Question

T-Mobile * 34%) 12:33 AM libproxy.library.unt.edu initialized): newr %Note this/giusttodsplaythe value 28. The following code was written by somebody who does not know how to use MATLAB efficiently Rewrite this as a single statement that will accomplish exactly the same thing for a matrix variable mat (e.g. vectorize this code) 29. Vectorize the following code. Write one assignment statement that would accomplish the same thing Assume that mat is a matrix variable that has been nitialized val%justfordsplay 30. Vectorize the following code. Write statement(s) that accomplish the same thing, eliminating the loop. Assume that there is a vector v that has a negative number in it, e.g newv% NoteAnttodisplay 31. Give some examples of when you would need to use a counted loop in MATLAB, and when you would not 32. For each of the following, decide whether you would use a for loop, a while loop, a nested loop (and if so what kind, e.g., a for loop inside of another for loop, a while loop inside of a for loop, etc.), or no loop at all DO NOT WRITE THE ACTUAL CODE sum the integers 1 through 50 add 3 to all numbers in a vector prompt the user for a string and keep doing this until the string that the user enters is a keyword in MATLAB: find the minimum in everycolumn of a matrix: prompt the user for 5 numbers and find their sum prompt the user for 10 numbers, find the average "

Explanation / Answer

I hope the code given is as follows

[r,c] = size(mat);
val = mat(1,1);
for i = 1:r
for j = 1:c
if mat(i,j) < val
val = mat(i,j);
end
end
end

The code is to get the smallest element in the matrix mat

Corresponding one line code


>> val = max(max(-mat))*-1;

Example output

>> mat

mat =

    3.1416   -1.4142   -1.0000    1.0000         0
    0.0000   -1.0000    1.0000    2.0000    1.0000
    1.0000    1.0000   -1.7321    1.0000    2.0000
   -1.0000   -1.0000    1.0000   -2.2361    3.0000

>> val = max(max(-mat))*-1;
>> val

val =

   -2.2361