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

 Réponse acceptée

James Tursa
James Tursa le 14 Sep 2018
Modifié(e) : James Tursa le 14 Sep 2018

6 votes

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

Plus de réponses (2)

José-Luis
José-Luis le 10 Août 2017

19 votes

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

3 commentaires

Fadal Sasse
Fadal Sasse le 10 Août 2017
Thanx
José-Luis
José-Luis le 10 Août 2017
Please accept the answer that best solves your problem.
PY SUN
PY SUN le 14 Sep 2018
Thanks

Connectez-vous pour commenter.

Drue
Drue le 22 Fév 2023

0 votes

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)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by