Question: function [ medianValue , meanValue ] = myArrayStats ( array 1 ) % Step 1 : Sort the array using the allowed 'sort' function sortedArray

function [medianValue, meanValue]= myArrayStats(array1)% Step 1: Sort the array using the allowed 'sort' function sortedArray = sort(array1); % Step 2: Calculate the median n = length(sortedArray); if mod(n,2)==1% Odd number of elements % Median is the middle value in the sorted array medianValue = sortedArray((n +1)/2); else % Even number of elements % Median is the average of the two middle values middle1= sortedArray(n /2); middle2= sortedArray(n /2+1); medianValue =(middle1+ middle2)/2; end % Step 3: Calculate the mean using a loop total =0; % Initialize sum for i =1:n total = total + array1(i); end meanValue = total / n; % Divide total by the number of elements end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!