How to identify partial string duplicates in a table

1 次查看(过去 30 天)
Hi,
I have a table of strings - see attached, and I want to be able to programatically identify and extract the identical part of the strings within that table.
For example, in the attached mat. the strings are:
'*EndoPart*' and '*EndoCort*'
Is there a way to identify the identical portion of the string ('Endo') in the entire column and extract it?
Thank you!

回答(1 个)

Stephen23
Stephen23 2020-11-28
Actually the identical part at the start of the string is '*Endo', and this is easy to find:
>> X = logical(cumprod(all(diff(TableExample.group,1,1)==0,1)));
>> TableExample.group(1,X)
ans =
*Endo
There is also an identical part at the end of the string 'rt*', but I assume that you only want the identical part at the start.
  2 个评论
David Mabwa
David Mabwa 2020-11-28
编辑:David Mabwa 2020-11-28
Yes I am only interested in the identical part at the start.
Thank you, it worked like a charm on the table example.
I however tried on my data and I keep getting this error:
"Check for missing argument or incorrect argument data type in call
"to function 'diff'
I have attached my table. I'm not sure what I am doing wrong.
% The code I run is identical and the datatype is the same.
% Might you have any idea whats going wrong here?
X = logical(cumprod(all(diff(TableExample2.group,1,1)==0,1)));
Thanks again
Stephen23
Stephen23 2020-11-28
@David Mabwa : I don't think I can open that table with the MATLAB versions I have available to me.
Perhaps someone else might be so kind as to investigate this further.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by