0

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.

Plot of values, maxima, minima

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
vittal rao
  • 17
  • 1
  • 8
  • Some sample data and expected result would be good... – kkuilla Jan 26 '15 at 17:33
  • Consider a 2*2 like : B = [-2 4 18 24 14 19 48 2 3 , -1 5 22 4 56 3 4 2 1] now what i need is the difference between max and min before that i.e in above case i expect difference between 48-14 = 34 and its indices which is B(1,5). The same way for other vector too. @kkuilla – vittal rao Jan 26 '15 at 17:45
  • 1
    @vittalrao - Why would the "minimum" be 14 in the above case when looking backwards at 48 when it's the maximum? Shouldn't the minimum be -2? Your problem statement and your example are contradictory. – rayryeng Jan 26 '15 at 20:54
  • @rayryeng- THats the whole point. if you could imagine it like a curve, i want to find the dip in curve that occurs before the peak. I want to find the index of this. In above example 14. Any ideas ? – vittal rao Jan 26 '15 at 23:17
  • It is difficult to imagine it like a curve. Please provide an [mcve](http://stackoverflow.com/help/mcve) with graphs, pictures etc so that we can make sense of your question. It is for a reason the help section advises the askers to create an [mcve](http://stackoverflow.com/help/mcve) – kkuilla Jan 27 '15 at 09:54
  • i have edited the post and added link to the plot. Sorry if i am not astill able to convey things concisely. – vittal rao Jan 27 '15 at 10:28
  • I don't know what is wrong, but I can suggest a way to avoid the `while` loop. Instead try `Bdiff = diff(B(i,1:o(i))); ind = find(Bdiff>0,1,'last')` to get the desired index `ind`. – Dave Kielpinski Jan 27 '15 at 11:38
  • @DaveKielpinski Diff apparently find difference between each matlab data. But i need the difference between the Global max and the minima before it. THe problem is locating this minima in the data. – vittal rao Jan 27 '15 at 12:14
  • @vittalrao Yes, that's what the `find` statement is for. – Dave Kielpinski Jan 27 '15 at 12:15
  • @DaveKielpinski tried this with a dummy array, seems to give a random index that doesnt make any sense. – vittal rao Jan 27 '15 at 16:10

0 Answers0