structをcellに変換する方法について
    8 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Koki Hashiguchi
 le 18 Mai 2020
  
    
    
    
    
    Commenté : Shunichi Kusano
    
 le 18 Mai 2020
            1×21 struct 5フィールドのstruct構造体配列を、21×5のcell配列として取り出したい場合に
struct2cell関数を用いると5×1×21のcell配列に変換されてしまいます。
21×5のcell配列として取り出すにはどのようにしたら良いでしょうか。
0 commentaires
Réponse acceptée
  Shunichi Kusano
    
 le 18 Mai 2020
        5x1x21のセル配列(以下A)をそのまま利用しまして、
newA = reshape(A, [5 21]).';
で21x5になります。reshapeで要素数1である2次元目を無視して5x21に。さらに.'で転置して、21x5にしています。
2 commentaires
  Shunichi Kusano
    
 le 18 Mai 2020
				すみません。セル配列には使えないと思い込んでいましたが、もっと簡単に書けるsqueeze関数というものがあります。
これを使って書きますと
newA = squeeze(A).';
で大丈夫です。これは要素数が1の次元を自動で削除してくれます。
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
