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

3 次查看(过去 30 天)
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.

采纳的回答

Tommy
Tommy 2020-4-29
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by