I want to be able to split an array of n rows and 5 columns into sections every time the data of a specific column (let's call it column3) crosses zero, and every time there is a peak or valley. I want the split of the array to happen to all the data (the conditions are based on column3, but are applied to all the columns).
The data also has repeated values for the whole data set; for those values I want to average the data of each column by considering the data that was averaged for a specific column per section.
if true%code example
column3 = [-6 -6 -6 -6 -5 -5 -3 -3 -3 -1 -1 -1 0 0 2 2 2 3 3 5 5 5 5 6 6 6 6 4 4 4 3 3 3 3 3 3 3 2 2 2 1 1 1 1 0 0 -1 -1 -2 -3 -5 -5 -5 -5 -5 -5 -5 -6 -6 -6];
end
I want this to end up looking like
if true %code result
column3_1 = [-6 -5 -3 -1 0]column3_2 = [0 2 3 5 6]column3_3 = [6 4 3 2 1 0]column3_4 = [0 -1 -5 -3 -5 -6]end
Then these changes should be also applied to the other columns based on the rows that were averaged for column3.
—–
My line of thought is first I must apply a code to average all the values that are repeated and in sequence using a loop, then separate the sections based on peaks, valleys, and crossing zeroes.
if true % code thought process
%first average all values
column3_avg = [-6 -5 -3 -1 -0 2 3 5 6 4 3 2 1 0 -1 -2 -3 -5 -6]%then divide into sections
column3_1 = [-6 -5 -3 -1 0]column3_2 = [0 2 3 5 6]column3_3 = [6 4 3 2 1 0]column3_4 = [0 -1 -5 -3 -5 -6]end
The main issue is that I can't seem to average only equal sequential data. Is there an effective way to do this on Matlab with a loop or am I better off doing it all by hand?
Thank you in advance
Best Answer