In an array (a) with indexes from 1 to m, I want to compare the values of this array one by one with each other, and if the distance (Difference) between two values is more than a value (z), for example, the difference between a(i) and a(j) at indexes i and j is more than z, I want to save these two indexes i and j and represent them in the output. I wrote these codes:
if abs(a(i)-a(j))> z disp(i); disp(j); fprintf('result is between %10.6f and %10.6f',i,j);end
but there is an error in if line:
Subscript indices must either be real positive integers or logicals.
How can I define indexes for matlab. Is a for loop (for i=1:m) needed for passing the array, If a loop is necessary, should I put fprintf out of the loop because it will repeat. For saving and representing the indexes i and j in the output, I'm looking for better functions besides disp or fprintf.
Best Answer