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!