!! Submission failed: unexpected error: Error using computeCost Too many output arguments.
Ältere Kommentare anzeigen
When I put this expression in MATlab I get:
!! Submission failed: unexpected error: Error using computeCost
Too many output arguments.
!! Please try again later.
function J = computeCost(X, y, theta)
data = load('ex1data1.txt');
m = 97;
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
error = h - y;
error_sqr = error.^2;
q = sum(error_sqr);
J = (1/ (2*m) * q)
3 Kommentare
Walter Roberson
am 15 Apr. 2020
Why are you overwriting the input X and y and theta?
What is the point of setting theta to 0 and then multiplying by theta ?
How can you be certain that data will always have exactly 97 rows?
Martin Felipe Wohlgemuth Pinzon
am 15 Apr. 2020
Walter Roberson
am 17 Apr. 2020
function J = computeCost(X, y, theta)
That line tells you that X, y, and theta are normally expected to be passed in as inputs.
data = load('ex1data1.txt');
m = 97;
Neither of those lines read or write X, y, or theta, so the input X, y, theta do not matter to those two lines.
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
The first of those lines ignores any X that was passed in and overwrites X with values. The second discards theta that was passed in and overwrites theta with zeros. The fourth line discards y that was passed in and overwrites y with values.
Therefore no matter what was passed in for X, y, theta, the code will ignore them and do its own thing.
Antworten (0)
Kategorien
Mehr zu Time Series Objects finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!