How to compare strings to other strings in the same array which contains regular digits

2 views (last 30 days)
Hi,
So I need to compare several string with eachother and want to know if there are dublicates which is not exactly the same.
An example of the strings are as follow F0_G70_C0 ; where the letters are always the same but the digits changes.
Sometimes there are other strings that follows but I only want to see if there are dublicates of what I wrote.
Is there a way to have a code that would work as if Fx_Gy_Cz = Fx_Gy_Cz; do ****, where then x,y,z are random digits.
Thank you in advance

Answers (1)

Rik
Rik on 1 Dec 2021
If the digits are the same, then the strings will be the same as well. So why not use strcmp?
strcmp('F1_G2_C3','F1_G2_C3')
Or (if you're actually using the string data type) you can even use equals:
"F1_G2_C3"=="F1_G2_C3"
  2 Comments
Rik
Rik on 2 Dec 2021
But if you want to check if the digits are the same, the string itself will be the same as well.
"F1_G2_C3"=="F1_G2_C4"
ans = logical
0
This is the case, even if you would extract the numbers and only compare those. If you're only after the same or not, why bother?
Or do you want to know whether the F is the same, even if the G and C values are different?
In that case I can recommend regexp to extract the values (or even textscan).

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by