MATLAB: Writting different length arrays in a CSV file

.csv filecell arraysvariable length

Hi All,
I have one variable with 19 cell arrays consists of different lengths (such as 1*26,1*30 etc). Now, I want to save them in a CSV or XLS or any other text format. But, I don't know how to save them as they have different lengths. Please kindly let me know, if is it possible? Or If I have to append NaN at the end of the lower lengths array. If So, How Can do that?
Please kindly give an example as I am not good with cell arrays.
Thanks

Best Answer

fid = fopen('YourOutputFile.txt', 'wt');
for K = 1 : length(YourCellArray)
this_row = YourCellArray{K}:
fprintf(fid, '%f,', this_row(1:end-1));
fprintf(fid, '%f\n', this_row(end) );
end
fclose(fid);