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

 Akzeptierte Antwort

Guillaume
Guillaume am 23 Mär. 2018
Bearbeitet: Guillaume am 23 Mär. 2018
structfun(@(fld) reshape(fld, 50, 1), yourstruct)
or
structun(@(fld) fld(:), yourstruct)

3 Kommentare

I did , I got this
Error using structfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
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)
Thanks very much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 23 Mär. 2018

Kommentiert:

am 23 Mär. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by