How do I concatenate cell arrays and line up the rows according to matching items in a column?

6 views (last 30 days)
Hi,
I have a few arrays (results from different tests) that all have the same first column (list of the participant IDs that performed the tests) which I want to combine into one large array. The thing is I dont know how to add them together and make sure that the rows match up according to the participant IDs.
If I use
high_questionnaires = horzcat(high_loc_ID_factors, high_empathy_ID_factors, high_itc_sopi_ID_factors)
then I get a cell array where the rows arent lined up correctly (see "high_concatenated").
Help is much appreciated!

Answers (1)

Dyuman Joshi
Dyuman Joshi on 27 Jul 2022
Edited: Dyuman Joshi on 28 Jul 2022
Sort by IDs and then join
[~,idhe]=sort(string(high_empathy_ID_factors(:,1)));
high_empathy_ID_factors=high_empathy_ID_factors(idhe,:)
[~,idhis]=sort(string(high_itc_sopi_ID_factors(:,1)));
high_itc_sopi_ID_factors=high_itc_sopi_ID_factors(idhis,:)
[~,idhl]=sort(string(high_loc_ID_factors(:,1)));
high_loc_ID_factors=high_loc_ID_factors(idhl,:)
high_questionnaires = horzcat(high_loc_ID_factors, high_empathy_ID_factors, high_itc_sopi_ID_factors)
  4 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by