how to solve this error horzcat Dimensions of matrices being concatenated are not consistent?

7 views (last 30 days)
hi all, how can i solve this error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent
in this code?
Error in Gauss (line 9)
Aug=[A b];
or this code:
function x=Gauss(A,b)
A=[0 4 2;10 -2 -7;-7 2 3];
b=[-24 10 15];
[m,n]=size(A);
if m~=n
error('A matriz deve ser quadrada');
end
nb=n+1;
Aug=[A b];
for k=1:n-1
for i=k+1:n
factor=Aug(i,k)/Aug(k,k);
Aug(i,k:nb)=Aug(i,k:nb)-factor*Aug(k,k:nb);
end
end
x=zeros(n,1);
x(n)=Aug(n,nb)/Aug(n,n);
for i=n-1:-1:1
x(i)=(Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);
end
x(i);
ps. i am new in matlab.
Cheers!

Accepted Answer

Walter Roberson
Walter Roberson on 6 Sep 2016
Your A is 3 x 3. You are trying to add on additional columns that are 1 x 3. You are asking that a matrix like this be constructed:
0 4 2 -24 10 5
10 -2 -7 X X X
-7 2 3 X X X
where the X represents a "hole", a non-existent location.
Matrices in MATLAB must be rectangular.
Hint:
b.'
  3 Comments

Sign in to comment.

More Answers (1)

Ratam Mahi
Ratam Mahi on 4 Apr 2018
Edited: Walter Roberson on 7 Apr 2018
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in Module1_Training (line 17)
db=[F c];

Community Treasure Hunt

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

Start Hunting!