How to vectorize the following code

9 次查看(过去 30 天)
Hi all,
I have the following code, is there any way to vectorize it?
RMH(1).D=rand(20,4);
RMH(2).D=rand(20,4);
a=zeros(length(RMH),numel(RMH(1).D));
for i=1:length(RMH)
a(i,:)=reshape(RMH(i).D,1,numel(RMH(i).D));
end
Thank you
Regards
Pietro
  2 个评论
Matt J
Matt J 2014-10-3
Your code doesn't run, so of course there's no way to vectorize it.
pietro
pietro 2014-10-3
you're on right. I have just fixed.

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-10-3
编辑:Andrei Bobrov 2014-10-3
a = reshape([RMH.D],[],numel(RMD))';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by