adding different number of columns to specific row

3 views (last 30 days)
I have 2 differnt csv files, i want to append the columns from book8 to book 7 based on the name column that appears in the 2 files, the name in 7 are unique but in 8 there are duplicates, so the appending columns may differ from row to another ...
is there a way to add the corresponding columns to a specific row?
i tried to append the columns in differnt ways with no success...
for row=(2:r) %

Answers (1)

Ridwan Alam
Ridwan Alam on 30 Jan 2020
Edited: Ridwan Alam on 30 Jan 2020
Try using the table join() method:
M_obs = readtable('book7.csv');
M_pri = readtable('book8.csv');
[~,M_pri_idx] = unique(M_pri(:,1));
M_pri_new = M_pri(M_pri_idx,:);
new_table = join(M_obs,M_pri_new,'Keys',[1,1]);
Hope this helps.
Shayma on 6 Feb 2020
sorry, I update the files, im trying to extend book7.csv with the columns from book8.csv
ZINC02619534 in row 3 at book7 will have the columns (2:end) from book8, from the rows 3,6,7
while ZINC02638599 for example will have the columns from book8 - row 13 only because it appears only once ..

Sign in to comment.


Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!