Vertical concatenation of cell array of different dimensions

13 ビュー (過去 30 日間)
SP
SP 2022 年 7 月 13 日
回答済み: Jash Kadu 2022 年 7 月 13 日
Hi,
I am having two cell array of different dimensions, like a = 1*28 and b= 1*30. I need to concatenate vertically and in the form of c = 2*30. The missing cells in cell array should be zero. How can I do this? Kindly help me with this. Thanks in advance.

採用された回答

Jash Kadu
Jash Kadu 2022 年 7 月 13 日
Hi,
a = 1*28
b = 1*30
By using this MATLAB will automatically fill missing elements with zeros.
a(numel(b)) = 0;
For Vertical concatenation:
c = [a;b]
c will now be 2*30
You can also refer to the following documentation for more information:

その他の回答 (1 件)

Chunru
Chunru 2022 年 7 月 13 日
% I am having two cell array of different dimensions, like a = 1*28 and b= 1*30.
% I need to concatenate vertically and in the form of c = 2*30. The missing cells
% in cell array should be zero
% Some example data
a = cell(1, 5); % 28
a{1} = rand(3); a{5}="abc";
b = cell(1, 7); % 30
b{1} = rand(2); b{7}="def";
c = num2cell(zeros(2,7)); % 30
c(1, 1:5) = a;
c(2, 1:7) = b;
c
c = 2×7 cell array
{3×3 double} {0×0 double} {0×0 double} {0×0 double} {["abc" ]} {[ 0]} {[ 0]} {2×2 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {["def"]}

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by