Minimum and maximum values of a field in a structure array

Hi. I have a strcuture array with 10 fields. How can, I find the minumum and maximum values of a particular field f1? I tried uisng min and max commands but, they are giving wrong results.
For example,
The name of the structure array is "Test" (1 x 5000) and the field name is "growth". I want the minimum and maximum of the whole field growth.
Test(1).growth=[1 2 3 4 5 5 6 7 8 9];
Test(2).growth=[10 20 40 67];
..... so on.
I want the maximum and the minimum of the field "growth".

2 件のコメント

madhan ravi
madhan ravi 2019 年 8 月 25 日
Could you illustrate with a short example?
SS
SS 2019 年 8 月 25 日
編集済み: SS 2019 年 8 月 25 日
The name of the structure array is "Test" (1 x 5000) and the field name is "growth". I want the minimum and maximum of the whole field growth.
Test(1).growth=[1 2 3 4 5 5 6 7 8 9];
Test(2).growth=[10 20 40 67];
..... so on.
I want the maximum and the minimum of the whole field growth.

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

 採用された回答

Bruno Luong
Bruno Luong 2019 年 8 月 25 日

0 投票

arrayfun(@(s) min(s.f1), s)

3 件のコメント

SS
SS 2019 年 8 月 25 日
編集済み: SS 2019 年 8 月 25 日
Hi. Thanks for your reply. The name of the structure is "Test" and the field name is "growth". I tried your code as follows: arrayfun(@(s) min(Test.growth), s)
It is giving the following error:
Error using min
Too many input arguments.
Error in @(s)min(Test.growth)
Did, I make any mistake in the syntax?
Bruno Luong
Bruno Luong 2019 年 8 月 25 日
編集済み: Bruno Luong 2019 年 8 月 25 日
I recommend you to post your data the next time asking question. You'll save time and us too.
arrayfun(@(s) min(s.growth), Test)
SS
SS 2019 年 8 月 25 日
編集済み: SS 2019 年 8 月 25 日
Thanks, will do it from next time onwards.

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

SS
2019 年 8 月 25 日

編集済み:

SS
2019 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by