Hi I need some help with matlab.
I have a matrix that’s 500 x 360. Below is a sample data set:
10 10 12 11 9 8 8 25 26 26 20 20 20
20 22 26 20 20 19 30 31 33 35 33 32
30 30 29 31 32 33 31 33 33 32 31 31
40 50 49 45 47 47 45 65 68 69 70 71
The code has to perform the following:
- Finds the first occurrence of a value I specify, in this case is a change of 20%. So observing (1,:), the first occurrence of a change of 20% is between column 2 and 3.
- Then it identifies the lowest value that occurred after the value specified in step 1. In this case is column 6 (i.e., value of 8). The code then measures the time elapsed from the value specified in step 1 to the lowest value that occurred in step 2. Looking back at the example, delta of 20% is (1,3) = 12, lowest value occurred after delta 20% is (1,6) = 8. Elapsed time is 3.
- The code then finds the highest value from the lowest value found in step 2. In this case is column 9 with a value of 26. It also records the time elapsed.
- Lastly, the code measure the time elapsed from the first delta value to the highest value found. In this case is the time from (1,3) to (1,9) which is 6.
So the output would look something like this:
12 8 3 26 3 6
26 19 3 35 4 3
NaN NaN NaN NaN NaN NaN
50 45 2 71 8 10
I appreciate your help. Thanks so much:)
I do not have access to matlab right now. But here are some steps to get you started.
Do double check the answers for your test case to see you get desired result.
Say you have a row vector
x. In your case say theith row of your data matrix i.e.x = data(i,:);Now to find the first occurrence of (say) 20% change you can use:
where
cIwill be the index of first value greater than 20% change andx(cI)is the required value.next to find the minimum after this value use
and to find the maximum after that:
finally to put all together:
This will work for your first row. Now for the third row you will need to make sure
cIhas a value. IfcIis empty then just useNaN(1,6).There will be similar error check if
cI+1orcI+minI+1exceed the number of elements. This will happen if the change you are looking for happens too late.For start you can set up a
for-loop over each row (i), but there has to be a better way to vectorize the code.Whole thing set up as using a
for-loop