Help with this problem
이전 댓글 표시
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?
채택된 답변
추가 답변 (3개)
fenam sogani
2017년 11월 5일
0 개 추천
function S = simple_stats(N) S = [mean(N,2),median(N,2),min(N,[],2),max(N,[],2)];
what meaning of 2 here
댓글 수: 1
Stephen23
2017년 11월 5일
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
ossai rex
2019년 5월 19일
0 개 추천
please what those [] and 2 stand for in the command line
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!