How do I combine data tables where there are different row lengths?

조회 수: 5 (최근 30일)
Amy Hughes
Amy Hughes 2019년 12월 14일
댓글: Ridwan Alam 2019년 12월 14일
From my cell arrays, I have converted each output into a table in matlab which I have attached as excel files for clarity ( I could not convert the cell outputs into character vectors of different lengths, so made them into tables instead).
Expected removal table contains 61 rows and 1 column (T1 in matlab)
Kept table contains 45 rows and 1 column (T2 in matlab)
Deleted table contains 16 rows and 1 column (T3 in matlab)
Please find attached my data.
How would I go about combining these tables together, when I want the rownames to align, and then the rest of the cells contain NaN or NA when they don't. I have attached an excel file with this done (combined_expect_kept_deleted). However, I need code to automate this.
If I could have converted the data into three separate character vectors, I would have used padcat to concatenate the vectors of different lengths, using NaNs etc. But my cell2mat does not work, and not sure how else to get the output into character vector format from a cell.
Does anybody have any suggestions please?

채택된 답변

Ridwan Alam
Ridwan Alam 2019년 12월 14일
T1(ismember(table2array(T1(:,1)),table2array(T2)),2) = T2;
T1(ismember(table2array(T1(:,1)),table2array(T3)),3) = T3;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by