How to construct a Row Vector

1 visualización (últimos 30 días)
M Salman Rashed
M Salman Rashed el 14 de Oct. de 2016
Comentada: M Salman Rashed el 14 de Oct. de 2016
I want to construct a row vector, with say, "L zeros", followed by a "1", and then again followed by "L Zeros"
What is the easiest command to do that? For example a= [ (0 0 0 ... L-1(0)) 1 (0 0 0 ... (L-1) 0)]

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 14 de Oct. de 2016
Editada: Andrei Bobrov el 14 de Oct. de 2016
L = 5; % or L = 1000
out = [zeros(1,L),1,zeros(1,L)];
  1 comentario
M Salman Rashed
M Salman Rashed el 14 de Oct. de 2016
Cheers Andrei Bobrov
Thanks but I got that by the time you answered... Off for the day now.,

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 14 de Oct. de 2016
Editada: KSSV el 14 de Oct. de 2016
Make a row zero matrix...and place one at the indices you want....
or
k = repmat([0 0 0 1],1,4)
  1 comentario
M Salman Rashed
M Salman Rashed el 14 de Oct. de 2016
Hi Dr Kolukula
What I am trying is just a single "1" in the centre of the row vector, with zeros preceding and following it. The length of the matrix can be anywhere from a few 10s to 1000s. I am looking for a simple generic command. As you see I am new to MATLAB.

Iniciar sesión para comentar.

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by