how to fill a matrix?
27 views (last 30 days)
Show older comments
Laura Echeverri Zea
on 8 Oct 2019
Answered: 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
Accepted Answer
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
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
More Answers (1)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!