Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Matrix replication
Replies: 2   Last Post: Nov 1, 2013 2:56 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
George

Posts: 13
Registered: 8/19/10
Matrix replication
Posted: Oct 31, 2013 5:35 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi all,

Here is a simple code in which a given matrix is replicated in five different ways:

% Matrix to be replicated
b=100*rand(12,12,2000);
% 1
tic
Id1 = (1 : size(b,1))';
Id2 = (1 : size(b,2))';
Id3 = (1 : size(b,3))';
Id4 = (1 : size(b,4))';
x1=b(Id1(:,ones(1,1)), Id2(:,ones(1,1)), Id3(:,ones(1,1)),...
Id4(:,ones(50),1));
toc
clear x1
% 2
tic
x2 = bsxfun(@plus, zeros(1,1,1,50), b);
toc
clear x2
% 3
tic
x3 = bsxfun(@times, ones(1,1,1,50), b);
toc
clear x3
% 4
tic
x4=repmat(b,[1 1 1 50]);
toc
clear x4
% 5
tic
x5=reparray(b,[1 1 1 50]);
toc
clear x5

Is anybody aware of another way to replicate matrices faster than the above? Or is there any possibility to improve appropriately any of the above methods to run faster?
Thank you in advance.

George Papazafeiropoulos



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.