im trying to create a function that wors the same way as the unique() function without using it

1 visualización (últimos 30 días)
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

Respuesta aceptada

Davide Masiello
Davide Masiello el 8 de Abr. de 2022
Editada: Davide Masiello el 8 de Abr. de 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)
uniqueA = 1×9
1 2 3 4 5 6 7 8 9
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.).

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by