MATLAB Answers

Pad with Nan according to maximum row in cell

21 views (last 30 days)
Charms
Charms on 27 Oct 2019
Answered: Fabio Freschi on 27 Oct 2019
Hi, I have a 1 x 8 cell (attached) and would like to cell2mat this matrix i.e to expand and show into one big numeric 97 x 8 array (97 being the maximum length of a cell array). I would also like to pad the ends of the smaller cell arrays with Nan to make all columns the same row length. How may I write for this?
Thank you!

  0 Comments

Sign in to comment.

Accepted Answer

Fabio Freschi
Fabio Freschi on 27 Oct 2019
I keep all steps separated
% the data
A = {rand(47,1),rand(80,1),rand(97,1)};
% pad with NaNs
A = cellfun(@(x)[x(1:end); NaN(97-length(x),1)],A,'UniformOutput',false);
% make a matrix
A = cell2mat(A);

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.