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월 13일
Thank you so much!
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