Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 可以对以下循环进行矢量化吗?

我有一个执行以下功能的for循环:

取M x 8矩阵,然后:
  1. 将其拆分为大小为512个元素的块(意味着X乘以矩阵的8 == 512,元素数量可以为128,256,512,1024,2048)
  2. 将块重塑为1 x 512(元素数)矩阵。
  3. 取矩阵的最后1/4放在前面,
    例如Data = [Data(1,385:512),Data(1,1:384)];
以下是我的代码:

for i = 1 : NumOfBlock if i == 1 Header = tempHeader(1:RowNeeded,:); Header = reshape(Header,1,BlockSize); %BS Header = [Header(1,385:512),Header(1,1:384)]; %CP Data = tempData(1:RowNeeded,:); Data = reshape(Data,1,BlockSize); %BS Data = [Data(1,385:512),Data(1,1:384)]; %CP start = RowNeeded + 1; end1 = RowNeeded * 2; else temp = tempData(start:end1,:); temp = reshape(temp,1,BlockSize); %BS temp = [temp(1,385:512),temp(1,1:384)]; %CP Data = [Data, temp]; end if i 1 temp = tempHeader(start:end1,:); temp = reshape(temp,1,BlockSize); %BS temp = [temp(1,385:512),temp(1,1:384)]; %CP Header = [Header, temp]; end start = end1 + 1; end1=end1 + RowNeeded; end 使用500万个元素运行此循环将花费超过1个小时的时间。我需要它尽快(以秒为单位)。这个循环能被向量化吗?



回答:

我再次感谢阿姆罗(Amro)给我一个解决问题的想法。抱歉,我在问题中没有明确表示自己。

这是我对问题的解决方案:

%#BS CDMA, Block size 128,512,1024,2048 BlockSize = 512; RowNeeded = BlockSize / 8; TotalRows = size(tempData); TotalRows = TotalRows(1,1); NumOfBlock = TotalRows / RowNeeded; CPSize = BlockSize / 4; %#spilt into blocks Header = reshape(tempHeader',[RowNeeded,8, 128]); Data = reshape(tempData',[RowNeeded,8, NumOfBlock]); clear tempData tempHeader; %#block spread & cyclic prefix K = zeros([1,BlockSize,128],'single'); L = zeros([1,BlockSize,NumOfBlock],'single'); for i = 1:NumOfBlock if i
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 01:02


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.