self made sorting numbers function
Mostrar comentarios más antiguos
I am trying to write my own sort function.. it gave me an error idk how to fix.
for j = 1:length(x)
for i = 1:length(x)-1
if x(i) < x(i+1)
minval = x(i);
val = x(i);
x(i) = [];
end
end
sortval(j) = val;
end
fprintf(sortval);
2 comentarios
Rik
el 6 de Mzo. de 2017
If you want to do this, you should at the very least loop backwards through your vector. You are removing elements, so at some point x will no longer have the length that your for-loops expect.
Cameron Stark
el 16 de Sept. de 2017
function b=downsort(b)
i=.5;
n = length(b);
while i<1
for x =1:n
if x ==n
i = 2;
break
end
if b(x) < b(x+1)
a = b(x);
b(x) = b(x+1);
b(x+1) = a;
break
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!