how to fill a matrix?

19 vues (au cours des 30 derniers jours)
Laura Echeverri Zea
Laura Echeverri Zea le 8 Oct 2019
Hi everyone. I'm trying to make code in which every time I run the code I have different values of X, and I what to save them in a matrix that changes size.
med = 8 (this value changes)
X = 2 (this value changes)
VecVal = zeros(1,med)
  5 commentaires
darova
darova le 8 Oct 2019
Exactly. Im curious
Laura Echeverri Zea
Laura Echeverri Zea le 8 Oct 2019
i'm sorry, im terrible expresing myself in eanglish...well, i don't know how to fill the matrix, because every time i run the code the matrix does only saves the new value and not the last ones, i dont know how to add the new mesurement values to the matrix with out deliting the ones from the other mesurements

Connectez-vous pour commenter.

Réponse acceptée

Fabio Freschi
Fabio Freschi le 8 Oct 2019
If I understand correctly
% number of measurements
med = 8;
% preallocation
VecVal = zeros(1,med);
% the measurement
X = 2;
% put it in a specified position, i.e. as first element
VecVal(1) = X;
  2 commentaires
Laura Echeverri Zea
Laura Echeverri Zea le 8 Oct 2019
thank you... and do you know how can i add another value of x to the matrix?
Fabio Freschi
Fabio Freschi le 8 Oct 2019
VecVal(2) = Y;
VecVal(3) = Z;
Or you can do this in a loop
for i = 1:5
X = myNiceEvaluation;
VecVal(i) = X;
end

Connectez-vous pour commenter.

Plus de réponses (1)

Laura Echeverri Zea
Laura Echeverri Zea le 8 Oct 2019
thank you :)

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