当我在Matlab中遇到警告时,我正在为Andrew Ng编写Coursera机器学习课程的函数.我没有写出答案应该是什么,但起始代码全部在这里,除了一行用于解释目的.问题不是捕获问题的答案,而是解释Matlab的警告.
我得到的警告(不是错误)说:
Line 6: The variable 'g' appears to be preallocated but preallocation is not recommended here
这是代码
function g = sigmoid(z)
%SIGMOID Compute sigmoid function
% g = SIGMOID(z) computes the sigmoid of z.
% You need to return the following variables correctly
g = zeros(size(z));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).
g = 1./z;
% =============================================================
end