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

4 views (last 30 days)
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.

Accepted Answer

Tommy
Tommy on 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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!