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

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Tommy
Tommy il 29 Apr 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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by