フィルターのクリア

How do I remove duplicates rows a struct in matlab?

36 ビュー (過去 30 日間)
ali froozani
ali froozani 2022 年 3 月 27 日
編集済み: Harshal Ritwik 2023 年 6 月 16 日
I want remove duplicates rows a struct in matlab.
  1 件のコメント
Image Analyst
Image Analyst 2022 年 3 月 27 日
Attach an example where one row is a duplicate of another row. It's not obvious from your screenshot which rows are duplicates of each other. To determine if the row is to be removed, do you want to check all columns, or just one of the columns? To you want to keep the the first cuplicated row, the last one, or neither one? Have you read this:

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

回答 (1 件)

Harshal Ritwik
Harshal Ritwik 2023 年 6 月 16 日
編集済み: Harshal Ritwik 2023 年 6 月 16 日
Hi,   
As per my understanding you want to remove duplicate rows in a structure in MATLAB. You can use ‘unique’ function to get the unique rows. However, the function doesn’t directly handle structs, so you need to modify the struct by converting it into a table by using the function ‘struct2table’. The following code snippet may help.
%Code Section
S(1).name = John; %Creating a Duplicate structure
S(1).score = 90;
S(2).name = John;
S(2).score = 85;
S(3).name = John;
S(3).score = 90;
T = struct2table(s); %Converting the structure to table
T_unique = unique(t); %Getting the unique rows from the table
Please refer to the following documentation for more information.
I hope it helps!
Thanks.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by