How do I replace the for loop for something quicker to plot?

조회 수: 3 (최근 30일)
Mvdw
Mvdw 2016년 6월 1일
편집: Mvdw 2016년 6월 1일
I'm plotting a stickfigure which is moving. To do this, I've to calculate the values of 26 points for every frame.
I do this using a for loop, but I believe there is a quicker way to do this.
  댓글 수: 1
Mvdw
Mvdw 2016년 6월 1일
편집: Mvdw 2016년 6월 1일
For more information:
I recorded with Xbox Kinect. From the Kinect I got translations and rotations. With those I calculate the positions of the joints in space.
But because I recorded a lot of frames, the for loop takes really long because for every frame the script has to do a big calculation, plot and do the calculation again for the next frame.
Here is a little piece of my script:
%load all information
twaist = [M(:,26) M(:,27) M(:,28)];
rwaist = [M(:,29) M(:,30) M(:,31)];
a=1;
b=size(M);
c=b(1,1);
for a=1:c;
%calculate the position of the joint in space
rxwaist=rwaist(a,1)*pi/180;
rywaist=rwaist(a,2)*pi/180;
rzwaist=rwaist(a,3)*pi/180;
ARwaist= [1 0 0;0 cos(rxwaist) -sin(rxwaist);0 sin(rxwaist) cos(rxwaist)];
BRwaist=[cos(rywaist) 0 sin(rywaist);0 1 0; -sin(rywaist) 0 cos(rywaist)];
CRwaist=[cos(rzwaist) -sin(rzwaist) 0; sin(rzwaist) cos(rzwaist) 0; 0 0 1];
Rwaist=ARwaist*BRwaist*CRwaist;
%creating a vector
ptwaist=[twaist(a,1);twaist(a,2);twaist(a,3)];
%Defining position (for waist is really simple, because this is my beginning point)
poswaist=ptwaist;
%Transpose
poswaist2=transpose(poswaist);
%creating lines between joints
pts_sw=[posspine2; poswaist2];
plot3(pts_sw(:,1), pts_sw(:,2), pts_sw(:,3),'g','LineWidth',1.5)
grid on
title('Stick Figure');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal
xlim([-80 80])
ylim([-50 200])
zlim([-310 -160])
drawnow
hold off
a=a+1;
end
So this script does these calculations for 26 joints per frame.
It is really slow but I don't know any other way to do this..

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2016년 6월 1일
You have not really provided anywhere near enough detail for us to help you, but my best guess is that you want the movie command.
  댓글 수: 1
Mvdw
Mvdw 2016년 6월 1일
I added some information. I hope you do understand my question now.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by