Mysort script error issue

2 visualizaciones (últimos 30 días)
Giha
Giha el 7 de En. de 2024
Comentada: Dyuman Joshi el 7 de En. de 2024
I am asking this question after quite some time since I have used Matab.
This is given mysort.m
and i am trying to drive to
but i am getting error on line4
can some one explain why am i getting error and, how to debug them?
  2 comentarios
Giha
Giha el 7 de En. de 2024
This is the code!
function y = mysort(x)
% Emulates the Matlab internal function ‘sort’
N = length(x);
for j = N:-1:2
track = x(1);
tracki = 1;
for i = 2:j
if x(i) > track
track = x(i);
tracki = i;
end
end
x(tracki) = x(j);
x(j) = track;
end
y = x;
Giha
Giha el 7 de En. de 2024
The function is applied in Matlab as shown:
>> y = [-10 8 -4 3 12 -15];
>> x = mysort(y);

Iniciar sesión para comentar.

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 7 de En. de 2024
Editada: Dyuman Joshi el 7 de En. de 2024
Remove the clear all, close all, clc line.
You generally don't need to use those commands, specially not inside a function.
Note that the file mysort() is not a script, it's a function.
Also, while asking a question here, you should share your code (by copy-pasting or sharing the file) instead of posting a picture of it.
  9 comentarios
Giha
Giha el 7 de En. de 2024
@Dyuman Joshi Thank you for helping! i got it to work with your comment!
Dyuman Joshi
Dyuman Joshi el 7 de En. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre White en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by