Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
helo,我有以下名为 stat.m 的函数
function [mean,stdev] = stat(x) n = length(x) mean = sum(x)/n stdev = sqrt(sum((x-mean).^2/n))
我将 x 定义为一个向量,它是 [1,2,5,7,9]
[1,2,5,7,9]
为什么当我键入时a = stat(x),matlaba = 5在命令提示符处返回最后一行?
a = stat(x)
a = 5
如果你想获得两个返回值,你必须这样做:
[a, b] = stat(x);
如果您只是这样做a = stat(x),MATLAB 会将其解释为您只需要第一个返回值。
因为a得到第一个参数mean
a
mean
试着叫它[a,b] = stat(x)
[a,b] = stat(x)