How to vectorize the following code

1 Ansicht (letzte 30 Tage)
pietro
pietro am 3 Okt. 2014
Kommentiert: pietro am 8 Okt. 2014
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 Kommentare
Matt J
Matt J am 3 Okt. 2014
Your code doesn't run, so of course there's no way to vectorize it.
pietro
pietro am 3 Okt. 2014
you're on right. I have just fixed.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 3 Okt. 2014
Bearbeitet: Andrei Bobrov am 3 Okt. 2014
a = reshape([RMH.D],[],numel(RMD))';

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by