Reshape a matrix in different way

1 回表示 (過去 30 日間)
Moe
Moe 2014 年 11 月 3 日
編集済み: per isakson 2014 年 11 月 3 日
Is there any other way to re-code this function (perhaps with for loop):
mmm = [2;3;4;8;9;11;13;14;15;16];
Dmm = zeros(2*size(mmm),1);
Dmm = reshape(bsxfun(@minus,2*repmat(mmm,1,2),[1 0])',1,[])'
  1 件のコメント
Adam
Adam 2014 年 11 月 3 日
There are always a multitude of different ways to program something and pretty much always a loop equivalent to vectorisation and bsxfun. The for loop equivalent should be easy enough to define though it's not obvious why you would want to - people usually wish to go in the other direction!

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

採用された回答

per isakson
per isakson 2014 年 11 月 3 日
編集済み: per isakson 2014 年 11 月 3 日
Is this Cody?
reshape( permute( cat( 2, 2*mmm-1, 2*mmm ), [2,1] ), [],1 )
or with fewer characters
reshape( permute( [2*mmm-1,2*mmm], [2,1] ), [],1 )
or
reshape( [2*mmm-1,2*mmm]', [],1 )

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by