how to solve this error horzcat Dimensions of matrices being concatenated are not consistent?
7 views (last 30 days)
Show older comments
victor caixeta
on 6 Sep 2016
Commented: Walter Roberson
on 16 Mar 2021
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!
0 Comments
Accepted Answer
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
Walter Roberson
on 16 Mar 2021
Aug=[A b];
was the existing code. The solution was to use
Aug=[A b.'];
More Answers (1)
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];
1 Comment
Walter Roberson
on 7 Apr 2018
What is size(F) and size(c) ?
In order to concatenate you need ndims(F) == ndims(c) and size(F,1) == size(c,1)
See Also
Categories
Find more on Linear Algebra 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!