Reshape a matrix in different way

1 view (last 30 days)
Moe
Moe on 3 Nov 2014
Edited: per isakson on 3 Nov 2014
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 Comment
Adam
Adam on 3 Nov 2014
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!

Sign in to comment.

Accepted Answer

per isakson
per isakson on 3 Nov 2014
Edited: per isakson on 3 Nov 2014
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 )

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!