function to find max values for intervals
Mostrar comentarios más antiguos
I have a single column with many values . I need to find the maximum value for the first 152 numbers. I need matlab to also output the max for the next 151, then the next 151 as well as the next 151. Then I need the max for the next 152 and then the next 151 and this same pattern repeats for all the data. The alternating 152 is what makes this task seemingly impossible .
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 27 de Dic. de 2019
It's not compact or cryptic but this brute force method is pretty easy to follow and understand.
r = rand(20418, 1); % Generate sample data.
counter = 1;
lenr = length(r)
for row = 1 : (152 + 3*151) : length(r)
row1 = row;
row2 = row1 + 151;
if row2 > lenr
break; % Quit if it would be beyond the end of the array.
end
fprintf('Getting means between row %d and %d, inclusive.\n', row1, row2);
theMeans(counter) = mean(r(row1:row2));
row1 = row2 + 1;
row2 = row1 + 150;
if row2 > lenr
break; % Quit if it would be beyond the end of the array.
end
fprintf('Getting means between row %d and %d, inclusive.\n', row1, row2);
theMeans(counter + 1) = mean(r(row1:row2));
row1 = row2 + 1;
row2 = row1 + 150;
if row2 > lenr
break; % Quit if it would be beyond the end of the array.
end
fprintf('Getting means between row %d and %d, inclusive.\n', row1, row2);
theMeans(counter + 2) = mean(r(row1:row2));
row1 = row2 + 1;
row2 = row1 + 150;
if row2 > lenr
break; % Quit if it would be beyond the end of the array.
end
fprintf('Getting means between row %d and %d, inclusive.\n', row1, row2);
theMeans(counter + 3) = mean(r(row1:row2));
counter = counter + 4;
end
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!