Accessing var content in column, not location

2 ビュー (過去 30 日間)
Smeagol
Smeagol 2012 年 10 月 13 日
I have a matrix of values with 4 columns. The left column is time in hrs. I am trying to find the max and min of the columns 2:4 and identify the time at which they occur, not the location.
(all is the name I defined for time and the temps)
all =
0 84.3000 90.0000 86.7000
2.0000 86.4000 89.5000 87.6000
4.0000 85.2000 88.6000 88.3000
6.0000 87.1000 88.9000 85.3000
8.0000 83.5000 88.9000 80.3000
10.0000 84.8000 90.4000 82.4000
12.0000 85.0000 89.3000 83.4000
14.0000 85.3000 89.5000 85.4000
16.0000 85.3000 88.9000 86.3000
18.0000 85.2000 89.1000 85.3000
20.0000 82.3000 89.5000 89.0000
22.0000 84.7000 89.4000 87.3000
24.0000 83.6000 89.8000 87.2000
I have been successful in finding the max and the location
[max_val,time_at] = max(all(:,2:4))
but the output is
max_val =
87.1000 90.4000 89.0000
time_at =
4 6 11
which returns the position in the first column, not the hour the max occurred. Any ideas how to modify for the time?
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 10 月 15 日
Please read the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

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

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 13 日
編集済み: Matt Fig 2012 年 10 月 13 日
Bad idea to name a variable 'all' as you will mask the ALL function!
A =[0 84.3000 90.0000 86.7000
2.0000 86.4000 89.5000 87.6000
4.0000 85.2000 88.6000 88.3000
6.0000 87.1000 88.9000 85.3000
8.0000 83.5000 88.9000 80.3000
10.0000 84.8000 90.4000 82.4000
12.0000 85.0000 89.3000 83.4000
14.0000 85.3000 89.5000 85.4000
16.0000 85.3000 88.9000 86.3000
18.0000 85.2000 89.1000 85.3000
20.0000 82.3000 89.5000 89.0000
22.0000 84.7000 89.4000 87.3000
24.0000 83.6000 89.8000 87.2000]
[Mx,Imx] = max(A(:,2:4));
[Mn,Imn] = min(A(:,2:4));
MXtime = A(Imx,1) % This holds the times at the max.
MNtime = A(Imn,1) % This holds the times at the min.

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 13 日
If you want time add
all(time_at,1)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by