Azzera filtri
Azzera filtri

how can i create a column vector with specific values?

79 visualizzazioni (ultimi 30 giorni)
Hello how are you? How can I create a column vector with specific values, that is, the first value would have to be 0, the second would have to be 63 up to 1, the vector would have to be as follows.
vec= [0
63
62
.
.
2
1]
any help is helpful.

Risposta accettata

Voss
Voss il 12 Giu 2022
vec = [0; (63:-1:1).']
vec = 64×1
0 63 62 61 60 59 58 57 56 55

Più risposte (1)

Dhritishman
Dhritishman il 15 Giu 2022
You can use the colon operator provided by MATLAB to create a vector with specified increment/decrement.
Writing
vec = 63:-1:1
vec = 1×63
63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34
will create a row vector of 63 consecutive values starting from 63 and going all the way down till 1.
But you need to transpose it so as to convert it into a column vector.
vec = (63:-1:1).'
vec = 63×1
63 62 61 60 59 58 57 56 55 54
Finally,
vec = [0; (63:-1:1).']
vec = 64×1
0 63 62 61 60 59 58 57 56 55
will return you a column vector with the first element as 0 and the next 63 consecutive numbers.

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by