How to vectorize the following code

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 Comments

Your code doesn't run, so of course there's no way to vectorize it.
you're on right. I have just fixed.

Sign in to comment.

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 3 Oct 2014
Edited: Andrei Bobrov on 3 Oct 2014
a = reshape([RMH.D],[],numel(RMD))';

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 3 Oct 2014

Commented:

on 8 Oct 2014

Community Treasure Hunt

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

Start Hunting!