简体   繁体   中英

matlab functions

helo, I have the following function called stat.m

function [mean,stdev] = stat(x)
n = length(x)
mean = sum(x)/n
stdev = sqrt(sum((x-mean).^2/n))

I defined x as a vector which is [1,2,5,7,9]

how come when I type a = stat(x) , matlab returns a = 5 for the last line at command prompt?

If you want to get both return values, you have to do this:

[a, b] = stat(x);

If you just do a = stat(x) , MATLAB interprets that to mean that you only want the first return value.

because a gets the first argument mean

try to call it [a,b] = stat(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM