Delete the line that are repeated

1 次查看(过去 30 天)
flashpode
flashpode 2021-7-19
回答: Matt J 2021-7-19
Hello, I made a code that compares two strings and what I want to do is to delete from the old strings the lines that are in the new one.
tf = strcmp(seq1,seq2);
disp('Comparing')
disp(seq1);
disp(seq2);
disp(tf);
if tf == 1
disp('Ha entrado al if')
M_conjunt = [M_conjunt,seq1];
end
I want to delete the ones that are in M_conjunt from both seq1 and seq2. I do not know how to do it. Thank youu!!!!
  3 个评论
Jan
Jan 2021-7-19
It is not clear, what the inputs seq1 and seq2 are: CHAR vectors, Strings, cell strings, string arrays?
The useful functions are: ismember, setdiff, union, unique.
flashpode
flashpode 2021-7-19
Are Strings. I use strcmp and I've used as you recomended ismember but the result is the same and I got the problem with the 0. because I want to do a matrix that contais only the messages that are just in AIS1 and not in common in AIS2 and I can't with those functions.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2021-7-19
what I want to do is to delete from the old strings the lines that are in the new one.
For example,
oldstring=["dog"; "fish"; "cat";"zebra"]
oldstring = 4×1 string array
"dog" "fish" "cat" "zebra"
newstring=["fish"; "zebra"]
newstring = 2×1 string array
"fish" "zebra"
difference=setdiff(oldstring,newstring)
difference = 2×1 string array
"cat" "dog"

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by