How do I find the corresponding dates for maximum prices?

2 ビュー (過去 30 日間)
stelios loizidis
stelios loizidis 2021 年 4 月 5 日
コメント済み: stelios loizidis 2021 年 4 月 5 日
Hello. I have a matrix A with dimensions 366x24 which contains values and a matrix B which contains dates-time (366x24 datetime). For each row of matrix A I found the maximum value (366X1). What I'm trying to do is find out on what date these maximum values correspond. Below is the code I wrote but the results it gives me are wrong.
Max_values=max(A,[],2);
Time_1=find(A==Max_values);
Time_of_max_values=B(Time_1);
Your help is important!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 5 日
[Max_values, Max_index] = max(A,[],2);
Time_of_max_values = B(Max_index)
This assumes that if multiple copies of the same maximum value appear in a row, that you only want to see one of them. If that is not true, then you need a redesign as each row would have a variable number of times associated.
arrayfun(@(rowidx) B(A(rowidx,:) == max(A(rowidx,:))), (1:size(A,1)).', 'uniform', 0)
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 5 日
Could you confirm that the year shown ins 1012? Not even 2012, but over 1000 years ago??
Can you attach your matrices for testing?
stelios loizidis
stelios loizidis 2021 年 4 月 5 日
Sorry. I mean 2012.
As for the matrices unfortunately i can not upload them

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

カテゴリ

Help Center および File ExchangeGet Started with Statistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by