I have a set of 18 MATLAB vectors (raw readings of current values) data that varies with many minimas and maximas put into a 2d matrix of B
which has a size of 18 by 16348.
I have found the indices and value of global max of each row vector.
Stored in another vector namely M
( has max values of each row vector of B
) and l (has indices of max of each row vector of B
). using the below code.
[M,l]=max(B,[],2)
Now i want to find the minima of each row vector that occurs before this global maxima.
I wrote a loop to look backwards, starting from global max and check for the least value and its indices. The condition for the minima can be imagined as b[i,l] < b[i,l-1] & b[i,l] < b[i,l+1]
This put in a loop is as below.
o=l; % l vector has the indices of global max of all 18 vectors%
for i=1:18
while ( B(i,o(i)) > B(i,o(i)-1)) % to locate the minima before globalmax
o(i)=o(i)-1;
end;
if( B(i,o(i) < B(i, o(i)+1))
display(o(i));
display(B(i,o(i)));
break;
end;
end;
For some reason the while
loop executes only once and then stops. That is the problem I am facing.
The plot below is showing 4 of the 18 values plotted and the maxima and minima for a vector marked.