Help with this problem
Show older comments
Hi. I am trying to solve this problem:
Write a function called simple_stats that takes a matrix N as an input and returns the matrix S as the output. S has the same number of rows as N. Each element of the first column of S contains the mean of the corresponding row of N. Similarly, the second column contains the median values; while the third column has the minimums. Finally, each element of the fourth column of S is equal to the maximum value of given row of N.
I wrote
function S = simple_stats(N)
S = [mean(N,1); median(N,2); min(N,[],3); max(N,[],4)]
but this is not working. any suggestions?
Accepted Answer
More Answers (3)
fenam sogani
on 5 Nov 2017
0 votes
function S = simple_stats(N) S = [mean(N,2),median(N,2),min(N,[],2),max(N,[],2)];
what meaning of 2 here
1 Comment
Stephen23
on 5 Nov 2017
Did you read the mean, median, min, and max documentation? The documentation clearly explains what all of the inputs mean.
one way i approached this is
a = mean(N,2);
b = median(N,2);
c = min(N,[],2);
d= max(N, [],2);
S = [a b c d]
i dont know if this makes sense
1 Comment
ossai rex
on 19 May 2019
0 votes
please what those [] and 2 stand for in the command line
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!