How to reshape every cell in a structure

4 vues (au cours des 30 derniers jours)
Blue
Blue le 15 Août 2019
Commenté : Blue le 15 Août 2019
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 ?

Réponse acceptée

madhan ravi
madhan ravi le 15 Août 2019
arrayfun(@(x) reshape(b(x).a, 12, 4), 1:numel(b), 'UniformOutput', false)
  6 commentaires
madhan ravi
madhan ravi le 15 Août 2019
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 le 15 Août 2019
Great, thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by