Clear Filters
Clear Filters

Unable to concatenate tables

3 views (last 30 days)
SereneGuy
SereneGuy on 13 Sep 2022
Commented: SereneGuy on 14 Sep 2022
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?

Answers (1)

Image Analyst
Image Analyst on 13 Sep 2022
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 Comments
SereneGuy
SereneGuy on 13 Sep 2022
Thank you so much!
SereneGuy
SereneGuy on 14 Sep 2022
@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?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!