I have an array which is increasing. At one point it starts to decrease. This trend starts repeating many times in array. How to extract only the decreasing portion from that array?

3 次查看(过去 30 天)
I have an array which is increasing. At one point it starts to decrease. This trend starts repeating many times in array. How to extract only the decreasing portions from that array and plot another array values which corresponds to that decreasing portion?

采纳的回答

Walter Roberson
Walter Roberson 2017-7-9
d = diff( YourArray(:).' ); %I assume it is a vector of unknown orientation
goes_down = strfind([0 d>0], [1 0]) + 1;
stops_going_down = strfind([0 d<0], [1 0]);
n_seg = length(goes_down);
segs = cell(1, n_seg);
for K = 1 : n_seg;
segs{K} = YourArray(goes_down(K) : stops_going_down(K));
end
  7 个评论
Tez
Tez 2017-7-25
How can I apply this code in multiple files?
d = diff( Col3 .' ); %I assume it is a vector of unknown orientation
mask = d < 0;
goes_down = strfind([0 mask], [0 1]) + 1;
stops_going_down = strfind([mask 0], [1 0]) + 1;
n_seg = length(goes_down);
idx2s = cell(1, n_seg);
seg2s = cell(1, n_seg);
seg3s = cell(1, n_seg);
for K = 1 : n_seg
idx2s{K} = goes_down(K) : stops_going_down(K);
seg2s{K} = Col3(idx2s{K});
seg3s{K} = Col2(idx2s{K});
end
segs23 = [seg2s; seg3s];
Walter Roberson
Walter Roberson 2017-7-25
When you process the multiple files, at each step do you want to forget about the previous file (except perhaps for the plot that has been drawn), or at each step do you want to add on to the seg2s / seg3s arrays so that you end up with one long cell array of those that includes all of the files, or do you want to use a cell array wrapping around each of those so that you can index into the cell array to get the seg2s / seg3s relevant to that file, or ....?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by