How to store a variable no. of data points in a matrix?
Show older comments
Hello everyone. The question is..suppose i am using a for loop. At the end of each loop it is giving me a data point only if a certain condition is satisfied otherwise not. I want to store these data points in a k*2 matrix where value of k depends on the condition being satisfied or not.So the no. of data points generated is not previously known. Is is possible to store the data points in a matrix if we dont know the exact dimension of the matrix at the first place?? Please help! Thanx!!
Accepted Answer
More Answers (1)
Mischa Kim
on 18 Jan 2014
Sure. Simply append the data point to the existing matrix of data points:
for ii = 1:N
...
if FLAG % if condition is true, append data point to matrix
data = [data; data_point];
...
end
end
Make sure that data_point is a 1x2 (row) vector.
Categories
Find more on Creating and Concatenating Matrices 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!