Create array with same number

681 visualizzazioni (ultimi 30 giorni)
Fadal Sasse
Fadal Sasse il 10 Ago 2017
Risposto: Drue il 22 Feb 2023
I have this command z=ones(length(x),1) If I want to change (ones) with 2 or 3 what I should do?

Risposta accettata

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

Più risposte (2)

José-Luis
José-Luis il 10 Ago 2017
twos = 2.* ones(length(x),1)
  3 Commenti
José-Luis
José-Luis il 10 Ago 2017
Please accept the answer that best solves your problem.
PY SUN
PY SUN il 14 Set 2018
Thanks

Accedi per commentare.


Drue
Drue il 22 Feb 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)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by