Compare positions of strings in two cell arrays having the same string elements

3 vues (au cours des 30 derniers jours)
Saeid
Saeid le 29 Avr 2020
Commenté : Saeid le 29 Avr 2020
I have two cell arrays F1 & F2 having the same elements, but the positions of elements in F2 have been shuffled:
F1 =
{'ETA.csv'} {'GAMMA_P.csv'} {'MAG.csv'} {'parameters.csv'} {'PRESSURE.csv'} {'shearhistogram.csv'}
F2 =
{'PRESSURE.csv'} {'ETA.csv'} {'MAG.csv'} {'shearhistogram.csv'} {'GAMMA_P.csv'} {'parameters.csv'}
Now taking e.g. F1 as reference, I would like to know what the position of every string of F1 is on F2.

Réponse acceptée

Tommy
Tommy le 29 Avr 2020
F1 = {'ETA.csv', 'GAMMA_P.csv', 'MAG.csv', 'parameters.csv', 'PRESSURE.csv', 'shearhistogram.csv'};
F2 = {'PRESSURE.csv', 'ETA.csv', 'MAG.csv', 'shearhistogram.csv', 'GAMMA_P.csv', 'parameters.csv'};
pos = cellfun(@(c) find(strcmp(c, F2)), F1)
gives
pos =
2 5 3 6 1 4

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings 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!

Translated by