how can i combine arrays of different size.

i have six arrays of size as given in figure.
i need to combine all arrays one after the other.
but the problem is they are of different dimenion.
how can i combine all these arrays?
thanks in advance.

4 Comments

That depends on how you want to make them the same size. Do you want to pad them with zeros? Or with NaN? Or do you want to interpolate?
Hm. You'll need to be more specific. For example, suppose your arrays were
A = [1 2 3 4;
5 6 7 8];
B = [1 2;
3 4;
5 6];
What should the combined array look like? Remember, numeric MATLAB arrays cannot have "empty spaces". But possibly you could pad with NaN. Or perhaps you need a cell array.
yes, pad with zeros.
zhoug zho
zhoug zho on 31 May 2021
Edited: zhoug zho on 31 May 2021
how can i combine these arrays by padding with NaN or zeros.?

Sign in to comment.

 Accepted Answer

sizes = cell2mat(cellfun(@size, YourCell(:), 'uniform', 0));
maxcols = max(sizes(:,2));
combined = cell2mat(cellfun(@(M) [M, zeros(size(M,1), maxcols-size(M,2))], YourCell(:), 'uniform', 0));

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!