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

Write a function with the following header: function [n_positive, n_negative, n_

ID: 3785693 • Letter: W

Question

Write a function with the following header: function [n_positive, n_negative, n_zero, n special] = my array metrics num (array) where: array is an arbitrary n times m array of class double. n_positive, n _negative, n_zero, and n_special are scalars of class double that represent, respectively, the number of strictly positive, strictly negative, zero, and "special" values in array. Special values are NaN, Inf, and -Inf. Note that Inf is both positive and "special", and -Inf is both negative and "special" Test cases: >>[[n _positive n_negative n_zero, n_special] = my array metrics num ([10]) n positive = 1 n negative = theta n_zero = theta n_special = theta >>array = (5, 0, 0, 1, 1, 7]; >>[n positive, n_negative, n_zero, n _special] = my array metrics num (array) n_positive = 3 n_negative = 1 n_zero =

Explanation / Answer

% matlab code

function[n_positive, n_negative, n_zero, n_special] = my_array_metrics_num(array)
n_positive = 0;
n_negative = 0;
n_zero = 0;
n_special = 0;
[n,m] = size(array);
for i=1:n
for j=1:m
if array(i,j) == Inf
n_positive = n_positive + 1;
n_special = n_special + 1;
elseif array(i,j) == -Inf
n_negative = n_negative + 1;
n_special = n_special + 1;
elseif array(i,j) == NaN
n_special = n_special + 1;
elseif array(i,j) < 0
n_negative = n_negative + 1;
elseif array(i,j) > 0
n_positive = n_positive + 1;
elseif array(i,j) == 0
n_zero = n_zero + 1;
  
end
end
end
end

array = [5, 0 , 0, Inf, -1 , 7];
[n_positive, n_negative, n_zero, n_special] = my_array_metrics_num(array);
disp("n_positive = ");
disp(n_positive);
disp("n_negative = ");
disp(n_negative);
disp("n_zero = ");
disp(n_zero);
disp("n_special = ");
disp(n_special);

%{
output:

n_positive =
3
n_negative =
1
n_zero =
2
n_special =
1

%}

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