# I want to apply bubble sort

11 vues (au cours des 30 derniers jours)
sm akash le 13 Jan 2020
Commenté : Sawyer Figol le 28 Nov 2020
%%%%%%%%Bubble sort %%%%%%
function A = bubbleSort(A)
n = length(A );
while n ~= 0
nn = 0;
for ii = 1:n-1
if A (ii) > A (ii+1)
[A(ii+1),A(ii)] = deal(A (ii), A (ii+1));
nn = ii;
end
end
n = nn;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%
A=[];
for a=1:emp(1)-1
[f,vec]=featureExtraction(sondos(G(nG,a)).block);
A(a,1:9)=f;
A(a,10)=sondos(G(nG,a)).position(1);
A(a,11)=sondos(G(nG,a)).position(2);
end
else
A=[];
for a=1:size(G,2)
[f,vec]=featureExtraction(sondos(G(nG,a)).block);
A(a,1:9)=f;
A(a,10)=sondos(G(nG,a)).position(1);
A(a,11)=sondos(G(nG,a)).position(2);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=bubbleSort(A);
for i=1:size(A,1)-1
similar=[];
for l=1:9 %num of features
s=abs(A(i+1,l)-A(i,l));
if s<s_threshold
%similar%
similar(l)=1;
else
%not similar%
similar(l)=0;
end
end
if isempty(find(similar==0)) %two block is similar calculat distance
x1=A(i,10);
x2=A(i+1,10);
y1=A(i,11);
y2=A(i+1,11);
D= sqrt((x1-x2)^2+(y1-y2)^2);
if D>Nd %calculate shift vector
rectangle('Position',[y1,x1,blocksize,blocksize],'Edgecolor','r');
rectangle('Position',[y2,x2,blocksize,blocksize],'Edgecolor','r');
% line([y1,y2],[x1,x2],'Color','r','LineWidth',1)
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%
when I run this,this error shows
Error using bubbleSort
Too many input arguments.
Error in DetectCM_Kmeans (line 86)
A=bubbleSort(A);
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

M le 13 Jan 2020
Modifié(e) : M le 13 Jan 2020
bubblesort is defined such that it takes only one input (the table to sort).
And you call it with two inputs : A=bubbleSort(A,9);
What does the 9 correspond to ?
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
sm akash le 13 Jan 2020
if I delete 9,same problem.but actually 9 is not here.

Connectez-vous pour commenter.

### Plus de réponses (1)

Michael Betts le 28 Nov 2020
f
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Sawyer Figol le 28 Nov 2020
f

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by