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
Can you please describe the process? Can you be more precise?
Laura Echeverri Zea
Laura Echeverri Zea on 8 Oct 2019
Edited: Image Analyst on 8 Oct 2019
i have to make measurements, so it will give everytime I'm going to have a different value of X, and i have to store those values each time so i can process them later on, but i don't know how many measurement i'm going to make, so i don't have the size of the matrix, so i created VecVal=zeros(1,med), where med is the number of measurements im making, and i want to start filling the matrix with the values of each measurement.
So? What's wrong with that?
darova
darova on 8 Oct 2019
Exactly. Im curious
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

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

thank you... and do you know how can i add another value of x to the matrix?
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)

Community Treasure Hunt

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

Start Hunting!