Borrar filtros
Borrar filtros

Adding Rows with Specific Values to Existing Variables

2 visualizaciones (últimos 30 días)
balsip
balsip el 13 de Oct. de 2016
Comentada: Star Strider el 13 de Oct. de 2016
Hello,
I have a 7x1 variable ("X1") to which I need to add a row at the beginning (cell value = 0) and a row at the end (cell value = 0). Obviously, I could do this manually, but I have many variables this needs to be done to.
My noodle is fried today. Apologies.

Respuesta aceptada

Star Strider
Star Strider el 13 de Oct. de 2016
Editada: Star Strider el 13 de Oct. de 2016
The easiest way is to concatenate zeros at the beginning and end of ‘X1’:
X1 = randi(9, 7, 1); % Create Data To Test Code
Result = [0; X1; 0];
  3 comentarios
James Tursa
James Tursa el 13 de Oct. de 2016
Editada: James Tursa el 13 de Oct. de 2016
The X1 = randi(9, 7, 1) was just to get some sample data. You can eliminate that line since you already have X1 with your actual data. Just do this:
Result = [0; X1; 0];
Star Strider
Star Strider el 13 de Oct. de 2016
Thank you, James!
Ambiguity now resolved (I hope).

Iniciar sesión para comentar.

Más respuestas (0)

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