Unable to concatenate tables

3 次查看(过去 30 天)
SereneGuy
SereneGuy 2022-9-13
评论: SereneGuy 2022-9-14
Hi,
I am new to Matlab. I use Matlab R2018b.
I have 2 tables (t1 and t2), first one is the size of 931x7, and the other one is 1x7. I want to concatenate them (later I will write it to Excel file).
I tried two ways:
t1 = [t1;t2];
t1 = cat(1,t1,t2);
None of them works, both gave me "Error using vertcat. Dimensions of arrays being concatenated are not consistent".
What did I do wrong?

回答(1 个)

Image Analyst
Image Analyst 2022-9-13
You can't have both numbers and characters in the same column, which is what you were trying to do. This works:
colHeaderExcel = {'Time_hour','Speed_ms_per_sec', ...
'LevelTime_hour','Level', ...
'Entries','TotalItem','BypassItem'};
reportMatrix = rand(9, 7);
t1 = array2table(reportMatrix,'VariableNames',colHeaderExcel);
t2(1,1).Time_hour = 0 ; '\nStatistics:\n\nAverage Write: xx\nAverate Read: yy\n';
t2(1,1).Speed_ms_per_sec = 0;
t2(1,1).LevelTime_hour = 0;
t2(1,1).Level = 0;
t2(1,1).Entries = 0;
t2(1,1).TotalItem = 0;
t2(1,1).BypassItem = 0;
t2 = struct2table(t2)
t2.Properties.VariableNames = t1.Properties.VariableNames;
t3 = [t1; t2]
t4 = cat(1,t1,t2) % Alternate operation
  4 个评论
SereneGuy
SereneGuy 2022-9-14
@Walter Roberson Btw, sorry to unaccept the answer. I just tried it, I still see the warning, unfortunately. Any other idea? Or did I miss something?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by