Compare two Vectors and multiply equal entries

1 次查看(过去 30 天)
Hi,
I got an orignal dataset with a set of IDs and a unique characteristic value for each ID. For example ID A has the characteristic value 1, ID B has 2 ID C has 3 and so on. I got a second array with entries like AABBCDDDEFFE and I want to create a resulting array that looks like 112234445665, how would you do that?
Thanks!

采纳的回答

Stephen23
Stephen23 2021-10-13
ID = 'ABCDEF';
val = 1:6;
arr = 'AABBCDDDEFFE';
[X,Y] = ismember(arr,ID);
out = val(Y(X))
out = 1×12
1 1 2 2 3 4 4 4 5 6 6 5

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by