Help with this problem
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (3)
fenam sogani
le 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 commentaire
Stephen23
le 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 commentaire
ossai rex
le 19 Mai 2019
0 votes
please what those [] and 2 stand for in the command line
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!