Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Amy Hughes
Amy Hughes le 14 Déc 2019
Commenté : Ridwan Alam le 14 Déc 2019
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?

Réponse acceptée

Ridwan Alam
Ridwan Alam le 14 Déc 2019
T1(ismember(table2array(T1(:,1)),table2array(T2)),2) = T2;
T1(ismember(table2array(T1(:,1)),table2array(T3)),3) = T3;
  2 commentaires
Amy Hughes
Amy Hughes le 14 Déc 2019
Thank-you very much.
Ridwan Alam
Ridwan Alam le 14 Déc 2019
Sure. Glad to help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by