I am trying to compare each element of an array with its subsequent elements and get the count of number of times the current element is greater than the subsequent elements.
the following is my code
function [ z ] = test(i,size_data, num,j,k,sum ) % test
num=xlsread('MKdata.xlsx');size_data=size(num);j=0k=0i=1for (i=i:size_data) if num(i) > num([i+1:size_data]) j=j+1 else k=k-1 end i=i+1 end sum=j+k end
the test data set i am using is
1733 3002 875 164 1464 1399 1039 1096 1812 2347 575 1393 411 283 1407 1294 1102 1886 3058 4587
results shows that every increment of i adds 1 to k and finally i get k=-20, j=0 whereas it should be 26
please guide me, please point out the mistake in logic or syntax
Best Answer