Flatten Matrix in Row Major Order in Arbitrary Dimensions

58 ビュー (過去 30 日間)
Lucas-Raphael Müller
Lucas-Raphael Müller 2019 年 6 月 12 日
回答済み: David Goodmanson 2019 年 6 月 15 日
Hey there,
is there a canonical way on how to flatten a arbitrarily high dimensional matrix in C order (i.e. row major, or last index first)? All I can find is for 2D which is comparably easy.
Cheers,

回答 (1 件)

David Goodmanson
David Goodmanson 2019 年 6 月 15 日
Hello Lucas-Raphael,
I'm not sure this is what you are looking for, but
B = permute(A,[6 5 4 3 2 1]); % (however many dimensions there are)
B = B(:);
has a lot of the right properties.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by