How to find maximum of individual cell array in its specific range

1 view (last 30 days)
Hi all, I have a cell structure consisting of multiple vectors(arrays)of different lengths. I want to find the maximums of these vectors and their locations at their specific ranges; let's say I want to find the maximum of the first halves of the vectors and of the second halves. I tried to accomplish this task by using the findpeaks function, but it is not necessary. So far I managed to write:
cut_Force... 1x123 1549992 cell
cut_Time... 1x123 1549992 cell
(data attached)
for c = 1 : length(cutTime)
[pks{c},locs{c}] = findpeaks(cut_Force{c},'MinPeakDistance',600);
indesiredrange1 = locs{c} > 0 & locs{c} < round(cellfun(@length,cutTime(c))/2);
Firstmax{c} = max(pks{c}(indesiredrange1));
locs_subset1{c} = locs{c}(indesiredrange1);
indesiredrange2 = locs{c} > round(cellfun(@length,cutTime(c))/2) & locs{c} < round(cellfun(@length,cutTime(c)));
Secondmax{c} = pks{c}(indesiredrange2);
locs_subset2{c} = locs{c}(indesiredrange2);
end
However, this code doesen't work for all the data (cutForce) I want to run through because of the 'MinPeakDistance', which in some cases gets more than one maximum and in some cases none. But I want to get exactly one maximum for every half of each vector. So I am looking for a more robust way.
I also tried to find these maximums using for loops, but also failed due to lack of programming knowledge:
Firstmax = [];
Secondmax = [];
%Searching for the maximums in the first halves of the vectors
for c = 1 : length(cutTime)
for d = 1 : round(cellfun(@length,cutTime(c))/2)
Firstmax{c} = max(cutForce{c}(d)); %I guess this loop is not appropriate
end
end
% Searching for the maximums' locations - this could probably be written in the
% previous loop
idx1 = [];
for c = 1 : length(cutTime)
idx1{c} = find([cutForce{c}] == Firstmax{c}); % ??
end
for c = 1 : length(cutTime)
for d = round(cellfun(@length,cutTime(c))/2) : (cellfun(@length,cutTime(c)))
Secondmax{c} = max(cutForce{c}(d));
end
end
idx2 = [];
for c = 1 : length(cutTime)
idx2{c} = find([cutForce{c}] == Drugi_vrh{c});
end
I am sure this can be done much easier in a shorter way. Any help will be appreciated.

Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!