Match text in cell array and copy to another
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
AHMED FAKHRI
le 21 Juin 2021
Commenté : Star Strider
le 22 Juin 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 commentaires
Réponse acceptée
Star Strider
le 21 Juin 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!