MATLAB Answers

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

4 views (last 30 days)
Saeid on 29 Apr 2020
Commented: Saeid on 29 Apr 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.

Accepted Answer

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)
pos =
2 5 3 6 1 4

More Answers (0)

Community Treasure Hunt

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

Start Hunting!