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

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!

 採用された回答

the cyclist
the cyclist 2016 年 6 月 20 日
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];

1 件のコメント

Dhaval Lodaya
Dhaval Lodaya 2016 年 6 月 20 日
Thank you very much! This works perfectly fine. Thanks
Regards, Dhaval

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAerospace Blockset についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by