I have different distribution for different time (t) with each distribution having 10,000 elements. I have following line of code which computes CDF for different distributions inside the loop with t varying from 1 to nT:
[f_CDF(:,t),x_CDF(:,t)]=ecdf(uncon_noise_columndata_all_nModels_diff_t(:,1,t));
Matlab’s function ecdf gives CDF values which could be less than the total number of elements in the distribution because the probability for the repeated elements gets added up. As a result, the output variables f_CDF and x_CDF run into problem of ??? Subscripted assignment dimension mismatch. error because of different length of vectors at different t.
How can I sort this problem such that NaN could fill up the places where the vector’s length is less than the maximum length of any vector in the whole matrix and I am able to implement the above line of code inside the loop. Thanks.
Here are two of many ways to approach this problem:
1) Use a cell array
Consider storing the results in a cell array instead of a matrix which, by definition, requires columns to have the same length.
[f_CDF{t},x_CDF{t}]=ecdf(uncon_noise_columndata_all_nModels_diff_t(:,1,t));2) Preallocate NaN matrices
Before running the loop which calculates the CDF results, create a matrix filled with NaNs. You know that each column won’t be longer than 10,000 records.