Dimensions of matrices being concatenated are not consistent

8 visualizaciones (últimos 30 días)
Hello. I have a series of output A=2, B=3, C=4,D=5, E=[1;0.1;0.9]. I'm trying to put all of these output together as a row matrix, F. i.e F = [A B C D E]. But i keep getting the error 'Dimensions of matrices being concatenated are not consistent'. Is there a solution to this please?
  3 comentarios
Rowland Ogunsola
Rowland Ogunsola el 22 de Ag. de 2020
Dimensions of matrices being concatenated are not consistent.
Function: gradientDescent
FileName: C:\Users\oguns\Desktop\MATLAB Projects\gradientDescent.m
LineNumber: 14
This is The error it says please... I dont seem to understand, cause in that specific line 14, the dimensions seems to be right.. m=97, and data is a 97x2 matrix.. can any one help please?
Image Analyst
Image Analyst el 22 de Ag. de 2020
I can't run an image. Post your script - your m-file - in a NEW question (not here in Chiamaka's 3 year old question). In the meantime, try using a semicolon to concatenate the column vector onto your scalar
X = [ones(m, 1); data(:, 1)];
This will stitch them one above the other, so if m=2:
1
1
d
d
d
Using a comma tries to stitch the data column vector to the right of a single number, so if m is 2:
1 d
1 d
d
Which won't work because all columns must have the same number of rows.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Jul. de 2017
Because E is a column vector, not a row vector like you're building with all the rest of the numbers, you must transpose E:
A=2
B=3
C=4
D=5
E=[1; 0.1; 0.9]
F = [A, B, C, D, E']
so now F is a row vector. Or else use semicolons and don't transpose E:
A=2
B=3
C=4
D=5
E=[1; 0.1; 0.9]
F = [A; B; C; D; E]
so now F is a column vector.

Más respuestas (2)

Suresh Lanka
Suresh Lanka el 21 de En. de 2020
A=2
B=3
C=4
D=5
E=[1; 0.1; 0.9]
F = [A, B, C, D, E']
  2 comentarios
Image Analyst
Image Analyst el 21 de En. de 2020
Yes, exactly what I said in my first answer.
Waqar Khan
Waqar Khan el 12 de Jun. de 2021
Sometimes inconsistence comes because your function def argu arrangments, and calling arg arrangements are not match. hope it will help too.

Iniciar sesión para comentar.


Ayobu Id
Ayobu Id el 18 de Abr. de 2022
Editada: Image Analyst el 18 de Abr. de 2022
>> A=['a' , 'b ';'c' ,'b']
Dimensions of matrices being concatenated are not consistent.
Help
  1 comentario
Image Analyst
Image Analyst el 18 de Abr. de 2022
Your Answer is not an Answer to @Chiamaka Agwuegbo.
This is an error you have because you're trying to make a character array with 3 characters in the first row (a, b, and a space), and two in the second row (c and b). If you get rid of the space it will work:
A=['a', 'b'; 'c', 'b']
A = 2×2 char array
'ab' 'cb'

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by