Azzera filtri
Azzera filtri

Unable to concatenate tables

3 visualizzazioni (ultimi 30 giorni)
SereneGuy
SereneGuy il 13 Set 2022
Commentato: SereneGuy il 14 Set 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?

Risposte (1)

Image Analyst
Image Analyst il 13 Set 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 Commenti
SereneGuy
SereneGuy il 13 Set 2022
Thank you so much!
SereneGuy
SereneGuy il 14 Set 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?

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by