how can I remove duplicate objects (not integers) from an array?

1 Ansicht (letzte 30 Tage)
tombola
tombola am 2 Feb. 2012
Bearbeitet: Adrian am 26 Sep. 2013
If I have an array of objects like those below, is there an easy way to remove duplicates please?
So, if two objects in the array have the ShareName of say "Oracle", one of them is removed?
MATLAB code
classdef Quote < handle
properties
ShareName='';
SharePrice=0;
end
Thanks a for any help,
Tom.

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 2 Feb. 2012
Hi,
something like this?
x = [Quote Quote Quote];
x(1).ShareName = 'foo';
x(2).ShareName = 'bar';
x(3).ShareName = 'foo';
[~,u]=unique({x.ShareName});
% get one of each ShareName:
x = x(u);
Titus

Weitere Antworten (0)

Kategorien

Mehr zu Construct and Work with Object Arrays finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by