How can one make this extraction?

I have a 3-D array where the first column is month, the second column is city, and the third column is a vector of temperature of the city in that month. I have previosuly sorted the temperature in the descending order. Then I now want to create a 3-D array where the first column is month, the second column is city, and the third columnis the n-th highest temperature of the month of the city. Please advise how to proceed.

 採用された回答

Steven Lord
Steven Lord 2022 年 7 月 15 日

0 投票

I have a 3-D array where the first column is month, the second column is city, and the third column is a vector of temperature of the city in that month.
So the array has size [N 3] for some value of N? That's not a 3-dimensional array. That's a matrix with three columns.
Then I now want to create a 3-D array where the first column is month, the second column is city, and the third columnis the n-th highest temperature of the month of the city.
I'm going to assume you mean that you want another matrix with three columns. As you've described it, you should use the groupsummary function. You can use the "Multiple Grouping Variables" or "Multiple Grouping Vectors for Vector Input" examples on that documentation page as a model.

4 件のコメント

alpedhuez
alpedhuez 2022 年 7 月 15 日
The array has
12 (months) * 10 (# of cities) * (30 records of temperature for each day of a month).
I want to create an array of
12*10*1 (highst temperture of the month of the city)
Torsten
Torsten 2022 年 7 月 15 日
編集済み: Torsten 2022 年 7 月 15 日
A = sort(A,3,'descent');
A = squeeze(A(:,:,1))
gives a 12x10 matrix with the highest temperatures in month i in city j.
alpedhuez
alpedhuez 2022 年 7 月 15 日
Thank you. Is there any simple way to extract the second highest, third highest,...?
Torsten
Torsten 2022 年 7 月 15 日
k-th highest:
A = squeeze(A(:,:,k))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

リリース

R2022a

タグ

質問済み:

2022 年 7 月 15 日

コメント済み:

2022 年 7 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by