Index exceeds the number of array elements. Index must not exceed 1. cosa posso fare per non far comparire questo errore? N=3 e il vettore w ha 3 elementi

5 次查看(过去 30 天)
function [ris] = ordin_genn(w,N)
for i=1:N-1
for j=i+1:N
if w(i)>w(j)
temp=w(i);
w(i)=w(j);
w(j)=temp;
end
end
end
ris=w;
disp("il vettore ordinato è ");
disp(ris);
end
  1 个评论
Santosh Fatale
Santosh Fatale 2022-11-9
编辑:Santosh Fatale 2022-11-9
Hi,
What is the relationship between input argument N and dimension of argument w? What is the dimesion of input argument w? I believe w is column vector.
Please correct me if I am wrong in understanding.

请先登录,再进行评论。

回答(1 个)

Khalid
Khalid 2022-11-9
Hi massimo,
I understand that you are facing the error for some inputs to the function "ordin_genn".
This error occurs whenever the value of N given to the function is greater than the number of elements in the array w.
So, to resolve this error you are required to give the value of N to be less than or equal to the number of elements in w for the function.
Hope this helps.
Regards,
Khalid

Community Treasure Hunt

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

Start Hunting!