How to vectorize the following code

조회 수: 11 (최근 30일)
pietro
pietro 2014년 10월 3일
댓글: pietro 2014년 10월 8일
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