Error using - Matrix dimensions must agree. HELP

1 view (last 30 days)
Priya
Priya on 22 Oct 2014
Answered: James Tursa on 22 Oct 2014
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?

Answers (1)

James Tursa
James Tursa on 22 Oct 2014
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.

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!