Consider the MATLAB script inside the box clear x 5 4 1 2 9

Consider the MATLAB script inside the box: clear; x - [-5 4 1 2 9]; for k = length(x):-2:1 if x (k) > 4 | x (k) 20 r = 10; elseif sum(x > 1) == 2 r = 20; else r = 0; end; After the MATLAB script is run, what are the variables y, z, and r equal to (their contents)? y = ? z = ? r = ?

Solution

% initial array x
x:     
-5   4   1   2   9

% for loop itearting over array x from the end alternating elements
k: 5   
x(5) = 9
y(5) = 10
       
k: 3   
x(3) = 1
y(3) = 2
       
k: 1   
x(1) = -5
y(1) = -4

% final array y,z and variable r
y:     
   -4    0    2    0   10
z:     
   21   16    3    4   91
       
r: 0

 Consider the MATLAB script inside the box: clear; x - [-5 4 1 2 9]; for k = length(x):-2:1 if x (k) > 4 | x (k) 20 r = 10; elseif sum(x > 1) == 2 r = 20;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site