필터 지우기
필터 지우기

Compare two string vectors with same input arguments but different length

조회 수: 5 (최근 30일)
Hi Guys,
I have two string arrays i want to compare. They both contain the same arguments, but in one of them some arguments are there twice or more times. My problem is, that i want to like give every argument an index number, so that in both string arrays the same argument has the same index.
For example: {a,b,c,d,e,f,g,h} and {a,a,b,c,d,d,d,e,e,f,g,h} are my strings. And i want to have two double arrays: (1,2,3,4,5,6,7,8) and (1,1,2,3,4,4,4,5,5,6,7,8).
Is it possible to make this work? Cause my string arrays, are about 25000 and 35000 rows long, and i need to put them in the "same" format, so i can procede with my script.
I would be grateful for every help i can get.
Greetings
Nils

채택된 답변

Paul
Paul 2021년 11월 18일
If stored in a cell arrary:
c1 = {'a','b','c','d','e','f','g','h'};
c2 = {'a','a','b','c','d','d','d','e','e','f','g','h'};
[~,ind] = ismember(c2,c1)
ind = 1×12
1 1 2 3 4 4 4 5 5 6 7 8
If actually stored as strings
s1 = string(c1)
s1 = 1×8 string array
"a" "b" "c" "d" "e" "f" "g" "h"
s2 = string(c2)
s2 = 1×12 string array
"a" "a" "b" "c" "d" "d" "d" "e" "e" "f" "g" "h"
[~,ind] = ismember(c2,c1)
ind = 1×12
1 1 2 3 4 4 4 5 5 6 7 8
  댓글 수: 1
Nils Pelzer
Nils Pelzer 2021년 11월 18일
Man! You are my hero. I´m not even joking. you solved all of my problems with this. Thank you so much! Appreciate the help!
Greetings

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by