Compare 2 strings without using ismember or strcmp

Hi, I've got a code that gives me different outputs and I want to compare the messages inside them and the ones that are not in one string(X) and are in the other(Y) write them into another output. Lets see:
K is the number of messages that has an string.
If K from X is not in Y = L
And I do not want to use ismember or srcmp because the proces would be very long.
I guess I have explained myself.
Thank youuu for the answer!!!

4 件のコメント

Stephen23
Stephen23 2021 年 9 月 27 日
@vicente Noguer: please give actual examples of X and Y that we can use, and the expected output.
DGM
DGM 2021 年 9 月 27 日
編集済み: DGM 2021 年 9 月 27 日
It's not really clear what your variables are or how they are arranged. This is how I read the problem statement:
"[I have] [two?] outputs and I want to compare the messages inside them ... [and I want to extract the ones that are unique to Y]"
Are these actual string arrays, or are they cell arrays of character vectors? Are they something else? Are there actually only two?
What about them would make the built-in tools exceptionally slow?
In some certain restricted cases, there are some faster alternatives to ismember(), but I don't know if any of that even applies, because I don't know what your variables are.
flashpode
flashpode 2021 年 9 月 27 日
編集済み: Walter Roberson 2021 年 9 月 27 日
a = [qwert34776;
dnfien/8863;
feihfidi234;
939405'cncieni;
300oppdf;
din2004ms;]
b = [qpwn3feini;
300oppdf;;
hfgt4568;
qwert34776;
dnfien/8863]
This could be an example of imputs and the output woulf be the ones that are in a that they are not in b.
And using ismember or strcmp slows the proces because the inputs I got have a lot of data to be comparing one by one
flashpode
flashpode 2021 年 9 月 27 日
I made an example of two imputs if you want the original inputs I can give you but they are this way mixing some letters with numbers and comas, etc

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2021 年 9 月 27 日
編集済み: Stephen23 2021 年 9 月 27 日

0 投票

Presuming that your examples with invalid syntax are actually supposed to be string arrays:
a = ["qwert34776";"dnfien/8863";"feihfidi234";"939405'cncieni";"300oppdf";"din2004ms"];
b = ["qpwn3feini";"300oppdf";"hfgt4568";"qwert34776";"dnfien/8863"];
c = setdiff(a,b)
c = 3×1 string array
"939405'cncieni" "din2004ms" "feihfidi234"
Most likely using SETDIFF will be faster than writing your own function (including time to write, time to test, time to debug, time to maintain, and runtime).

1 件のコメント

flashpode
flashpode 2021 年 9 月 27 日
Yeah that really help!! Thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

タグ

質問済み:

2021 年 9 月 27 日

コメント済み:

2021 年 9 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by