Error using - Matrix dimensions must agree. HELP
Mostra commenti meno recenti
addpath('C:\Program Files\MATLAB\R2012a\Matlab\q1')
load x.dat
load y.dat
x=(X-mean(X))./std(X);
y=(Y-mean(Y))./std(Y);
m=length(x);
x=[ones(m,1),x];
alpha=0.07;
theta=[0;0];
MAX_ITR=100;
J=zeros(MAX_ITR,1);
for num_iteration=1:MAX_ITR
J(num_iteration)=(0.5/m).*((x*theta)-y)'*((x*theta)-y);
grad=(1/m).*x'*((x*theta)-y);
theta=theta-alpha.*grad;
end
fprintf('Theta values are ...\n')
theta
R=(y-x*theta).^2;
fprintf('RMS values is ....\n')
sqrt(sum®./m)
plot(J)
Error using - Matrix dimensions must agree.
Can anyone help me how to get rid of this error?
Risposte (1)
James Tursa
il 22 Ott 2014
0 voti
The best course of action usually is to get into the debugger and stop your code at the line that is generating the error, and then examine the variable sizes. Once you figure out which variables are the wrong (or unexpected) size, you can work back in the code to figure out why and work toward a solution.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!