how to store values into array/matrix with different number of rows and only one column
33 views (last 30 days)
Hi, how i want to store values from loop which has only 1 cols but may have different numbers rows.
For example, in 1st loop the result is
Meanwhile 2nd loop the results is
Thus, i want to store it as:
Is it possible? Since within the loop...the row can be any numbers.
Rik on 6 Aug 2021
Edited: Rik on 6 Aug 2021
It is best to pre-allocate your output array as close to the size you think you need, because extending a matrix hurts performance substantially.
est_rows=5;%estimate of the largest number of rows
if col==1 ,part_result=(1:2).';
result((keep_rows+1):end,:)=;%will only crop unused rows