Merge rows with similar names

15 ビュー (過去 30 日間)
Vlatko Milic
Vlatko Milic 2021 年 10 月 22 日
コメント済み: Vlatko Milic 2021 年 10 月 27 日
Hi,
I have a table consisting of ten columns. In the first column, each row has a unique name. However, many rows have the same starting four letters. I would like to merge the rows with the same starting letters, and perform some calculations based on these rows.
Thanks in advance!
  3 件のコメント
Vlatko Milic
Vlatko Milic 2021 年 10 月 22 日
I mean concatenate. I.e. to group the into the same rows, or vectors. I know how to do it if I had the same row names all over, however, it is only in the beginning the row names are the same.
Thanks Stephen
Image Analyst
Image Analyst 2021 年 10 月 22 日
@Vlatko Milic, you keep forgetting to attach your data in a .mat file with the paperclip icon. Here's another chance to read the posting guidelines:

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

採用された回答

Pranjal Kaura
Pranjal Kaura 2021 年 10 月 26 日
Hey Vlatko,
It's my understanding that you want to group/merge rows with similar names. The criteria for 'similarity' is that they must have the same first 4 letters. You also mention that you know how to merge/group these rows when using complete row names for judging similarity, but are facing issues while merging using only a subset of the row name.
Here is a code snippet using which you can identify which rows are similar, using only the first 'n' letters. This will provide you with a number (say group number) for every row. 'Similar' rows would have the same number You can then merge them using your custom code.
A = ["Pizza", "Hello", "Hellbound", "Yesterday", "Yesss", "Yesman"]; % your first column
n = 3; %number of initial alphabets to consider
A2 = extractBetween(A(:), 1, n);
A_groups = unique(A2);
[~,A_groupNum] = ismember(A2, A_groups) %this will assign a number to every row. Similar rows would have the same number
Hope this helps!
  1 件のコメント
Vlatko Milic
Vlatko Milic 2021 年 10 月 27 日
Hi Pranjal,
That is exactly what I was looking for. Thanks a lot for your thorough answer and your time.
Kind regards

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by