How would i store data into a vector

28 vues (au cours des 30 derniers jours)
Feliciano Döring
Feliciano Döring le 16 Avr 2018
What i want to do is create a vector with only 1's that has a varying size depending on how i want it to be, since i know dynamically creating variables is not good i thought about creating a matrix of zeroes and storing the values i want in it, how would i do that? Also if there is another way of doing it please help.

Réponse acceptée

David Fletcher
David Fletcher le 16 Avr 2018
Modifié(e) : David Fletcher le 16 Avr 2018
numElements=10;
%Create 1x10 row vector filled with zeros
rowVector=zeros(1,numElements)
%Create 1x10 column vector filled with ones
colVector=ones(numElements,1)
colVector(5)=10 %Store the value 10 in the fifth element of colVector
rowVector(2)=22 %Store the value 22 in the second element of rowVector
  1 commentaire
Feliciano Döring
Feliciano Döring le 16 Avr 2018
Perfect, thanks! I didn't know you could use 'ones' likes 'zeroes'

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by