Why does this function stop at 25.?

2 views (last 30 days)
cale man
cale man on 25 May 2015
Commented: Stephen23 on 25 May 2015
With notation:
Subscripted assignment dimension mismatch.
Error in slider8 (line 24)
X(:,Iter)=Xtemp; V(:,Iter)=Vtemp; A(:,Iter)=Atemp;
What should I cange to make this function works with plot?
The code of m.file (1)
1. % Set up the time interval and the initial positions of the nine coordinates
2. T_Int=0:0.01:2;
3. X0=[0 50 pi/2 125.86 132.55 0.2531 215.86 82.55 4.3026];
4. global T
5. Xinit=X0;
7. % Do the loop for each time interval
8. for Iter=1:length(T_Int);
9. T=T_Int(Iter);
10. % Determine the displacement at the current time
11. [Xtemp,fval] = fsolve(@constrEq4bar,Xinit);
13. % Determine the velocity at the current time
14. phi1=Xtemp(3); phi2=Xtemp(6); phi3=Xtemp(9);
15. JacoMatrix=Jaco4bar(phi1,phi2,phi3);
16. Beta=[0 0 0 0 0 0 0 0 2*pi]';
17. Vtemp=JacoMatrix\Beta;
19. % Determine the acceleration at the current time
20. dphi1=Vtemp(3); dphi2=Vtemp(6); dphi3=Vtemp(9);
21. Gamma=Gamma4bar(phi1,phi2,phi3,dphi1,dphi2,dphi3);
22. Atemp=JacoMatrix\Gamma;
23.
24. % Record the results of each iteration
25. X(:,Iter)=Xtemp; V(:,Iter)=Vtemp; A(:,Iter)=Atemp;
27. % Determine the new initial position to solve the equation of the next
28. % iteration and assume that the kinematic motion is with inertia
29. if Iter==1
30. Xinit=X(:,Iter);
31. else
32. Xinit=X(:,Iter)+(X(:,Iter)-X(:,Iter-1));
33. end
35.end
36.% T vs displacement plot for the nine coordinates
37.figure
38.for i=1:9;
39. subplot(9,1,i)
40. plot (T_Int,X(i,:))
41. set(gca,'xtick',[], 'FontSize', 5)
42.end
43.% Reset the bottom subplot to have xticks
44.set(gca,'xtickMode', 'auto')
45.
46.% T vs velocity plot for the nine coordinates
47.figure
48.for i=1:9;
49. subplot(9,1,i)
50. plot (T_Int,V(i,:))
51. set(gca,'xtick',[], 'FontSize', 5)
52.end
53.set(gca,'xtickMode', 'auto')
54.
55.% T vs acceleration plot for the nine coordinates
56.figure
57.for i=1:9;
58. subplot(9,1,i)
59. plot (T_Int,A(i,:))
60. AxeSup=max(A(i,:));
61. AxeInf=min(A(i,:));
62. if AxeSup-AxeInf<0.01
63. axis([-inf,inf,(AxeSup+AxeSup)/2-0.1 (AxeSup+AxeSup)/2+0.1]);
64. end
65. set(gca,'xtick',[], 'FontSize', 5)
66.end
67.set(gca,'xtickMode', 'auto')
7%The code of m.file3
68.% Determine the positions of the four revolute joints at each iteration
69.Ox=zeros(1,length(T_Int));
70.Oy=zeros(1,length(T_Int));
71.Ax=80*cos(X(3,:));
72.Ay=80*sin(X(3,:));
73.Bx=Ax+260*cos(X(6,:));
74.By=Ay+260*sin(X(6,:));
75.Cx=180*ones(1,length(T_Int));
76.Cy=zeros(1,length(T_Int));
77.
78.% Animation
79.figure
80.for t=1:length(T_Int);
81. bar1x=[Ox(t) Ax(t)];
82. bar1y=[Oy(t) Ay(t)];
83. bar2x=[Ax(t) Bx(t)];
84. bar2y=[Ay(t) By(t)];
85. bar3x=[Bx(t) Cx(t)];
86. bar3y=[By(t) Cy(t)];
87.
88. plot (bar1x,bar1y,bar2x,bar2y,bar3x,bar3y);
89. axis([-120,400,-120,200]);
90. axis normal
91.
92. M(:,t)=getframe;
93.end
  3 Comments
Walter Roberson
Walter Roberson on 25 May 2015
At the time the problem happens, what are size(Xtemp), size(Vtemp), size(Atemp), and size(JacoMatrix) ?
Stephen23
Stephen23 on 25 May 2015
Instead of posting the code as text (with annoying line-numbers), please upload the whole Mfile using the paperclip button that you will find above the textbox. You will need to push both buttons: Choose file and Attach file.
Then please delete the code from your question.

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!