Match text in cell array and copy to another
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
AHMED FAKHRI
am 21 Jun. 2021
Kommentiert: Star Strider
am 22 Jun. 2021
Hi
I have a cell array (one of many) that looks like this: on the left is the sector name. On the right is the emission value of that sector.
Let us assume the name of the cell array is E30
'Coal Mine (open)' 0.016182475
'Food & Drink' 0.004392493
'Gas Platform' 0.00377076
'Gas Terminal' 0.023197913
'Glass' 0.031353608
'LNG Terminal' 0.027425894
'NRMM' 0.421852383
'Oil Terminal' 0.093687465
'Other Iron and Steel' 0.004623789
'Other Minerals' 0.004241753
'Other industry' 6.61E-05
'Paper' 0.002562681
'Vehicles' 0.000265986
I want to copy the values only to the cooreponding exact row (sector name) and E30 column in the new array below (leaving the empty sectors as they are)
Sector E25 H25 CCS25 E30
'Coal Mine (open)'
'Food & Drink'
'Gas Platform'
'Gas Terminal'
'Glass'
'NRMM'
'Oil Terminal'
'Other Chemicals'
'Other Iron and Steel'
'Other industry'
'Paper'
'Vehicles'
'Ammonia'
'Refining'
'LNG Terminal'
'Non ferrous metal'
'Iron (Port Talbot Scunthorpe)'
'Lime'
'Oil Platform'
'Other Minerals'
'Cement'
'Ethylene'
'Compressor Station'
'Construction'
'Other Fuel Production'
'Waste Processing'
Is there please general way to do that? If you want these info above as Excel, these are attached.
Many thanks
0 Kommentare
Akzeptierte Antwort
Star Strider
am 21 Jun. 2021
This is the best I can do with that. It will likely require a bit of editing later (with respect to the variable names).
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/659855/E30.xlsx';
T1 = readtable(filename)
[dir,fname,ext] = fileparts(filename)
T1.Properties.VariableNames = {'Sector',fname}
C2 = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/659860/Mapping.xlsx');
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/659860/Mapping.xlsx')
T2 = innerjoin(T1,T2,'Keys','Sector')
This should get you started. Experiment further to get the result you want. See the documentation on innerjoin (and its friends) to understand how best to use them.
.
8 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Export 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!