In: Computer Science
z = [ 100 93 90 89 80 79 78 75 67 60 45 42 41 40 30 20 15 12 10 9 2 1]
Using MATLAB, Write fully vectorized code (no loops) to find index number of which the numbers have decreased by 40. Print results to command window.
MATLAB Code:
% MATLAB fully vectorized code (no loops) to find index number of which the numbers have decreased by 40.
% Initializing vector
z = [ 100 93 90 89 80 79 78 75 67 60 45 42 41 40 30 20 15 12 10 9 2
1];
% Storing index values
indices = 1:length(z);
% Finding index of elements that are decreased by 40
idxLess40 = indices(z < 40);
% Printing to command window
disp(idxLess40);
_____________________________________________________________________________________________________
Sample Run: