Efficient application of unique and strcat functions

2 ビュー (過去 30 日間)
Maria
Maria 2014 年 8 月 10 日
編集済み: per isakson 2014 年 8 月 23 日
I use the following code on several occasions to keep only the rows with the condition that X elements don't repeat:
[~, ind,~] = unique(strcat(a(:,2)a(:, 6)));
a = a(ind,:);
In this case I keep the rows that have different combinations of the elements of column 2 and 6.
I use the functions unique and strcat because they work for cell type variables with both strings and numbers . The problem is that this code is not efficent and takes a lot of time to run. I was wondering if someone had a better solution. Thank you

採用された回答

Matt J
Matt J 2014 年 8 月 10 日
編集済み: per isakson 2014 年 8 月 23 日
Looks like you need the 'rows' flag in your call to unique. Also, it might help to avoid requesting additional output arguments that you don't need.
a = unique(strcat(a(:,2),a(:,6)),'rows');
Note that the use of ~ output arguments isn't the same as requesting fewer outputs. The ~ outputs will still be computed. They just won't be stored anywhere.

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by