How to find index and copy data to the another table having same label?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
HCLEE
am 9 Nov. 2022
Kommentiert: Star Strider
am 9 Nov. 2022
Hi,
There are 'table1' and 'table 2' which have same index labels.
The table 1 has data and I want copy them to the table 2 as shown in below picture.
I'm not sure which code is prefer to me.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 9 Nov. 2022
I would experiment by vertically concatenatating the two tables and then use sortrows on the result to sort them by the first column. I can’t fiund the appropriate documentation just now, however that would work just like vertically concatenating arrays —
Table3 = [Table1; Table2]
T1 = array2table(randi(9, 5, 4), 'VariableNames',{'1st class','2nd class','mass(kg)','conc(%)'})
T2 = array2table(randi(9, 5, 4), 'VariableNames',{'1st class','2nd class','mass(kg)','conc(%)'})
T3 = [T1; T2]
T3 = sortrows(T3,1)
That approach at least works when I test it here.
.
2 Kommentare
Star Strider
am 9 Nov. 2022
The point I make here is that you can vertically concatenate both tables, and that is likely what you want to do. The sortrows call simply sorts the first column to get the desired result (so all the ‘A’ values are at the top, the ‘B’ values next, and so for the rest).
Copying the values from one table to another would mean vertically concatenating the tables and then sorting them. This is not (at least as it appears to me) a join operation, although you can certainly experiment with that if you so desire.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!