How to merge cell arrays with different dimensions?

4 ビュー (過去 30 日間)
Ivan Mich
Ivan Mich 2022 年 2 月 2 日
回答済み: Ivan Mich 2022 年 11 月 5 日
I have two cell arrays. The first one (A) has 1x14 cells, and the second (B) has 1x7 cells. I would like to create an array (or a table) that would consists of two arrays in vertical merging. The commands e.g. table(A,B) etc. shows me error about the dimensions of each one.
Could you please help me ?
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 2 月 2 日
What would be the expected size and datatype of the "two arrays in vertical merging" ?
Are you looking for an output table with 14 variables, with the first row being the content of A, and the first 7 entries of the second row being the content of B, and with the second 7 entries of the second row being some kind of padding (such as empty cells) ?
Ivan Mich
Ivan Mich 2022 年 2 月 2 日
Yes , Just like that you mentioned @Walter Roberson

サインインしてコメントする。

採用された回答

Ivan Mich
Ivan Mich 2022 年 11 月 5 日
system('copy file1.txt+file2.txt+file3 OUTPUT_Merged_file.txt');
This is the solution

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 2 月 2 日
T = table(A{:});
temp = cell(1, length(A));
temp(1:length(B)) = B;
T = [T; temp];
Note that using [] between a table and a cell array has the effect of inserting the content of the cell array as additional rows in the table.
  5 件のコメント
Ivan Mich
Ivan Mich 2022 年 2 月 3 日
let me explain, I mean I would like to have one output file with:
  • the first line of A (1x14)
  • the second line of B (1x7)
  • the third line of data (19x3)
These three bulltes must be merged vertically, in the order I mentioned above, in the final aoutput file.
could you please help me to make it?
Ivan Mich
Ivan Mich 2022 年 11 月 5 日
system('copy file1.txt+file2.txt+file3 OUTPUT_Merged_file.txt');
This is the solution

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by