im trying to create a function that wors the same way as the unique() function without using it
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
haarn sumhah
il 8 Apr 2022
Modificato: Davide Masiello
il 8 Apr 2022
i first wrote it as a stand along program
clear, clc
nput = [1 2 3 4 4 5 5 6 7 8 9];
%function bmatch = findmatch(nput)
q = intersect(nput,nput);
sim = 1 - isequal(q,nput);
if sim == 0;
disp('0')
else sim == 1;
disp('1')
end
then tried to change it to a function but couldnt get it to output anything please help
clear, clc
nput = [1 2 3 4 5 6 7 8 2 9];
function sim = ismatch(nput)
q = intersect(nput,nput);
sim = 1 - isequal(q,nput);
if sim == 0;
disp('0')
else sim == 1;
disp('1')
end
end
0 Commenti
Risposta accettata
Davide Masiello
il 8 Apr 2022
Modificato: Davide Masiello
il 8 Apr 2022
This is rudimentary, but it might be a starting point.
clear, clc
A = [1 2 3 4 5 6 7 8 2 9 2 1 5];
uniqueA = ismatch(A)
function out = ismatch(A)
B = A == A';
B(logical(eye(size(B))) | logical(tril(ones(size(B))))) = 0;
out = A(~any(B,1));
end
However, it still does not do eveything that unique does (sort output, indexes of duplicates etc.).
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Stress and Strain in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!