how to fill a matrix?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Laura Echeverri Zea
le 8 Oct 2019
Réponse apportée : 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
Réponse acceptée
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
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
Plus de réponses (1)
Voir également
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!