I wrote a feature for the Coursera Andrew Ng machine learning course when I met a warning in Matlab. I did not write that I should answer, but the source code is here, except for one line for explanation. The question is not to fish to answer the problem, but the explanation for Matlab's warning.
The warning (not the error) that I get says:
Line 6: The variable 'g' appears to be preallocated but preallocation is not recommended here
Here is the code
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
source share