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일
structfun(@(fld) reshape(fld, 50, 1), yourstruct)
or
structun(@(fld) fld(:), yourstruct)

댓글 수: 3

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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

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