how to predefine a matrix with one unknown dimension
Show older comments
hey everybody I am interested in predefining a matrix with unknown dimension. I know that the matrix should have 15 rows (number of iterations), but the number of columns (time stages) depends on a stop condition in the code, and hence can't be known in advance. can I create a general definition like v=[]; but for a matrix with one known dimension? In addition, is it possible to create a zero matrix with 1 unknown dimension?
thanks!
1 Comment
Eliraz Nahum
on 13 Oct 2018
Moved: Dyuman Joshi
on 18 Oct 2023
Accepted Answer
More Answers (1)
Image Analyst
on 13 Oct 2018
Just define a matrix that's well large enough to hold all your numbers, like a few million elements or whatever.
v = zeros(15, 1000000);
Then do whatever you need to do assigning rows and columns in v, then, if you've kept track of the max column number, you can simply crop the array
v = v(:, maxColumn);
Categories
Find more on Programming 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!