V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7];
To determine hwo many time the values goes up or down, you need two counters:
Now you have to step through the elements and compare the current element with the previous one. This cannot work for the first element, so start with the 2nd:
for k = 2:length(V)
disp(V(k))
end
Comparing with the previous element works like: V(k) < V(k - 1)
Now you can insert two IF commands using the corresponding conditions and increase the value of the concerned counter.
Instead of the IF command, you can use the fact, that the logical comparison replies TRUE and FALSE, which is converted to 1 or 0 automatically in arithmetic expressions:
x = 0;
x = x + (10 > 9)
x = x + (10 > 12)
Now try it and post your code in case of troubles.
Best Answer