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

 Accepted Answer

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

3 Comments

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)

Sign in to comment.

More Answers (0)

Categories

Asked:

on 23 Mar 2018

Commented:

on 23 Mar 2018

Community Treasure Hunt

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

Start Hunting!