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

1 view (last 30 days)
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 on 1 Dec 2021
If the digits are the same, then the strings will be the same as well. So why not use strcmp?
Or (if you're actually using the string data type) you can even use equals:
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.
ans = logical
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.


Find more on Characters and Strings in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by