A = [1 2; 3 4];
B = [4 5 6; 7 8 9];
C = [10 11 12 13; 14 15 16 17];
D = {A,B,C};
mat_sizes = cellfun(@(x) size(x), D, 'UniformOutput', 0)';
max_dims = max(cell2mat(mat_sizes), [], 1);
result = cellfun(@(x,y) ...
padarray(x, [0, max_dims(2)-size(x,2)], 'post'), ...
D', mat_sizes, 'UniformOutput', 0);
result = cell2mat(result);
1 Comment
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/510035-how-to-append-matrices-of-different-sizes-together#comment_807878
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/510035-how-to-append-matrices-of-different-sizes-together#comment_807878
Sign in to comment.