Alternative of REPMAT routine when working with BSXFUN for a large vector
3 次查看(过去 30 天)
显示 更早的评论
Dear coder, To make thing clear, I will explain the situation with reference to details along with the code below
%%In simple form, the case can be understand as the following
DataSet=5; % 5 data points for each subject
TotalSub=1;
T_sub1=rand((DataSet*TotalSub),1); % For first subject
T_sub2=rand((DataSet*TotalSub),1); % For Second subject
Constant_s=rand(5,2); % Column 1 & 2 represent T1 and T2 respectively
%%Multiplication between each subject to the constant
T_sub1_Constant_s=bsxfun(@times,T_sub1,Constant_s);
T_sub2_Constant_s=bsxfun(@times,T_sub2,Constant_s);
%%In a compact form, we solve similar problem such as
NSub=2; % Assume we have two subjects
T_sub1N2=rand((DataSet*NSub),1); % For first and second subject
Constant_s_rp=repmat(Constant_s,NSub,1); % HOW TO avoid using REPMAT?
T_sub1N2_Constant_s=bsxfun(@times,T_sub1N2,Constant_s_rp);
Yet, as the size of the Constant_s and total subject increase, the vector become extremely large, and using repmat to create these matrices become slower and worse consume to much memory.
I wonder if there is other ways to make the computation fast and memory efficient. I also try KRON, but it does not give me the desired output.
Thanks in advance.
2 个评论
Jan
2017-12-6
The question would be easier to understand, if you simply provide some test data created by rand(). What are the sizes of a and b? Without your help_repmat.mat file, this is impossible to find out. Which vector becomes "extremely large" and how large is this in absolute numbers?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!