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 views (last 30 days)
Show older comments
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 Comment
Santosh Fatale
on 9 Nov 2022
Edited: Santosh Fatale
on 9 Nov 2022
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.
Answers (1)
Khalid
on 9 Nov 2022
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!