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
    조회 수: 2 (최근 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
    
 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
    
 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 
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!