How to find minimum value within specific segments of a matrix using Vectorization?

2 views (last 30 days)
I have the following matrix:
A=[1 0.1; 1 0.15; 1 0.35; 1 0.22; 2 0.45; 2 0.69; 2 0.33;...600 0.27; 600 0.34; 600 0.22];
Here first column (numbers 1, 2...600) represents time and second column (numbers 0.1, 0.15,0.35 etc.) represents fuel consumption. I need to find the value of minimum fuel consumption for each time period( for time=1s there will be a single min value and so on for each time) and store it in another array. This is just a example and actual number of data points are very large and using of for loops is time consuming. How can I solve this problem using Vectorization method or without using any loops? Thanks in advance!

Accepted Answer

the cyclist
the cyclist on 20 Jun 2016
A = [1 0.1;
1 0.15;
1 0.35;
1 0.22;
2 0.45;
2 0.69;
2 0.33;
600 0.27;
600 0.34;
600 0.22];
[uniqueA,~,jj] = unique(A(:,1));
uniqueMin = accumarray(jj,A(:,2),[],@min);
uniqueAandMin = [uniqueA,uniqueMin];

More Answers (0)

Categories

Find more on Programming 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!