Combining matrix of different dimension.
2 次查看(过去 30 天)
显示 更早的评论
I have three matrix. Matrix 1 = [2 2; 0 0],Matrix 2 =[1 1;0 0] and Matrix 3=[2 2 2 2 ;3 3 3 3] . I will like to combine these 3 matrix such that it becomes [2 2 0 0;0 0 0 0;1 1 0 0;0 0 0 0;2 2 2 2;3 3 3 3]. Appreciate your kind assistance. Thanks.
0 个评论
采纳的回答
Andrei Bobrov
2017-7-26
m1 = [2 2; 0 0];
m2 =[1 1;0 0];
m3=[2 2 2 2 ;3 3 3 3];
C = {m1,m2,m3};
[r,c] = cellfun(@size,C);
m = max([r(:),c(:)]);
for ii = 1:numel(C)
if any([r(ii),c(ii)] < m)
C{ii}(m(1),m(2)) = 0;
end
end
out = cat(1,C{:})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!