How to reshape every cell in a structure
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I am trying to reshape every cell in a 1x4 structure with 10 fields. A simplified example would look like this but when I try to reshape every 1x48 cell into 4x12 cells I get the following error: Inputs to STRUCTFUN must be scalar structures.
b = struct('a', {[1:48], [1:48], [1:48], [1:48]})
structfun(@(a) reshape(a, 12, 4), b, 'UniformOutput', false)
Thoughts ?
댓글 수: 0
채택된 답변
madhan ravi
2019년 8월 15일
arrayfun(@(x) reshape(b(x).a, 12, 4), 1:numel(b), 'UniformOutput', false)
댓글 수: 6
madhan ravi
2019년 8월 15일
fn = fieldnames(b);
for k = 1:numel(b)
for l = 1:numel(fn)
b(k).(fn{l})= reshape(b(k).(fn{l}), 4, 12);
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!