how to fill a matrix?

27 views (last 30 days)
Laura Echeverri Zea
Laura Echeverri Zea on 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 Comments
darova
darova on 8 Oct 2019
Exactly. Im curious
Laura Echeverri Zea
Laura Echeverri Zea on 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

Sign in to comment.

Accepted Answer

Fabio Freschi
Fabio Freschi on 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 Comments
Laura Echeverri Zea
Laura Echeverri Zea on 8 Oct 2019
thank you... and do you know how can i add another value of x to the matrix?
Fabio Freschi
Fabio Freschi on 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

Sign in to comment.

More Answers (1)

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

Community Treasure Hunt

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

Start Hunting!