Create array with same number

I have this command z=ones(length(x),1) If I want to change (ones) with 2 or 3 what I should do?

 Respuesta aceptada

James Tursa
James Tursa el 14 de Sept. de 2018
Editada: James Tursa el 14 de Sept. de 2018

6 votos

See this link for a discussion of various methods to do this:
The fastest method seems to be
z = zeros(length(x),1) + 2;

Más respuestas (2)

José-Luis
José-Luis el 10 de Ag. de 2017

19 votos

twos = 2.* ones(length(x),1)

3 comentarios

Fadal Sasse
Fadal Sasse el 10 de Ag. de 2017
Thanx
José-Luis
José-Luis el 10 de Ag. de 2017
Please accept the answer that best solves your problem.
PY SUN
PY SUN el 14 de Sept. de 2018
Thanks

Iniciar sesión para comentar.

Drue
Drue el 22 de Feb. de 2023
To create arrays with the same number I'd personally just set a variable and put it in the linspace function
x = 3
poof = input('how many columns of this number do you want?')
linspace(x,x,poof)

Categorías

Etiquetas

Preguntada:

el 10 de Ag. de 2017

Respondida:

el 22 de Feb. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by