Error using - Matrix dimensions must agree. HELP
显示 更早的评论
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?
回答(1 个)
James Tursa
2014-10-22
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!