Compare two Vectors and multiply equal entries

조회 수: 1 (최근 30일)
Dom
Dom 2021년 10월 13일
답변: Stephen23 2021년 10월 13일
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에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by