Eliminating duplicated values in a cell Array

My cel Array looks as such:
S = {'ABS' ; 'First'; 'input'; 'ABS'}
it is a column array instead of a row. I want to eliminate any and all duplicate values in the cell array. I tried the unique function with and without cell2mat and I am getting an error both ways. What is the best way I can go about eliminating duplicate values in my cell array?

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 3 月 4 日
編集済み: KALYAN ACHARJYA 2020 年 3 月 4 日

0 投票

S = {'ABS' ; 'First'; 'input'; 'ABS'};
result=unique(S)
result
result =
3×1 cell array
'ABS'
'First'
'input'

5 件のコメント

Deon Hargrove
Deon Hargrove 2020 年 3 月 4 日
Tried that and I am getting this error: Input A must be a cell array of character vectors.
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 3 月 4 日
Can you share the code screenshot and error message?
Deon Hargrove
Deon Hargrove 2020 年 3 月 4 日
Sure. I cant pos the full code, but esentially I am creating an app that is getting the name of blocks from a simulink block. In the below code I am getting the block type from all the blocks in a specific library
Error using cell/unique (line 85)
Input A must be a cell array of character vectors.
Error in blockDetection (line 56)
result = unique(ControlsBlocksType);
Error in modelCheck/RunCleanupButtonPushed (line 187)
blockDetection(app);
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 207)
callback(app, event);
ControlsBlocksType = ControlsBlocksType';
result = unique(ControlsBlocksType);
Stephen23
Stephen23 2020 年 3 月 4 日
@Deon Hargrove: please upload the cell array in a .mat file by clicking the paperclip button.
Deon Hargrove
Deon Hargrove 2020 年 3 月 4 日
here it is

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

カテゴリ

質問済み:

2020 年 3 月 4 日

コメント済み:

2020 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by