Borrar filtros
Borrar filtros

Insert first element into existing column vector...

22 visualizaciones (últimos 30 días)
David Pesetsky
David Pesetsky el 13 de Jun. de 2018
Respondida: alfiya riyas el 26 de Dic. de 2019
Hello,
I am trying to just insert a 0 into my 48x1 double vector z, like this:
array = [0.0,z]
I keep getting:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
What am I missing?
  1 comentario
Stephen23
Stephen23 el 13 de Jun. de 2018
@David Pesetsky: What shape do you expect the output to be, when you concatenate these together horizontally: [1x1,48x1]. The first has one row, the second has 48 rows... how many rows should the output have? How many columns?

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 13 de Jun. de 2018
You should join them by using vertcat. Note that your z is row matrix.
z = rand(48,1) ;
array = [0.0 ;z] % method 1
array = vertcat(0,z) % or use vertcat
  2 comentarios
David Pesetsky
David Pesetsky el 13 de Jun. de 2018
I used the:
array = [0.0 ;z]
method. I never saw a semicolon used like that. I had a space, and a comma. Both failed.
Stephen23
Stephen23 el 13 de Jun. de 2018
@David Pesetsky: how to define matrices is explained in the introductory tutorials:
These explain many basic concepts that are invaluable for using MATLAB.

Iniciar sesión para comentar.

Más respuestas (1)

alfiya riyas
alfiya riyas el 26 de Dic. de 2019
In a column contains char vaues 'F' and 'M'.
i want to add values again 1 0 -1 in the same column using for loop
no of rows 6106 an the column no is 2
how to add these numbers usinf for ands if loop

Categorías

Más información sobre Matrix Indexing 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