Unable to concatenate tables

3 visualizaciones (últimos 30 días)
SereneGuy
SereneGuy el 13 de Sept. de 2022
Comentada: SereneGuy el 14 de Sept. de 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?

Respuestas (1)

Image Analyst
Image Analyst el 13 de Sept. de 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 comentarios
SereneGuy
SereneGuy el 13 de Sept. de 2022
Thank you so much!
SereneGuy
SereneGuy el 14 de Sept. de 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?

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by