reshaping a Structure using structfun command and reshape

Hi:
I want to apply the command function structfun to a structure which has 16 fields each of size (5 rows and 10 columns)
Assume one of the fields is:
A= rand(5,10)
B=reshape(A,50,1)
I want to do this for every field (Matrix) in this structure.
Best regards

 採用された回答

Guillaume
Guillaume 2018 年 3 月 23 日
編集済み: Guillaume 2018 年 3 月 23 日

1 投票

structfun(@(fld) reshape(fld, 50, 1), yourstruct)
or
structun(@(fld) fld(:), yourstruct)

3 件のコメント

Haidi Bob
Haidi Bob 2018 年 3 月 23 日
I did , I got this
Error using structfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
Guillaume
Guillaume 2018 年 3 月 23 日
Oh yes, I'd forgotten that structfun doesn't return a structure by default. Well, just do what the error message tells you
structfun(@(fld) reshape(fld, 50, 1), yourstruct, 'UniformOutput', false)
or
structun(@(fld) fld(:), yourstruct, 'UniformOutput', false)
Haidi Bob
Haidi Bob 2018 年 3 月 23 日
Thanks very much.

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2018 年 3 月 23 日

コメント済み:

2018 年 3 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by