How to reshape every cell in a structure

3 ビュー (過去 30 日間)
Blue
Blue 2019 年 8 月 15 日
コメント済み: Blue 2019 年 8 月 15 日
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 ?

採用された回答

madhan ravi
madhan ravi 2019 年 8 月 15 日
arrayfun(@(x) reshape(b(x).a, 12, 4), 1:numel(b), 'UniformOutput', false)
  6 件のコメント
madhan ravi
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
Blue
Blue 2019 年 8 月 15 日
Great, thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by