Info

This question is closed. Reopen it to edit or answer.

TimerFcn, Error using VertCat?

1 view (last 30 days)
Mohsin
Mohsin on 27 Jun 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
This is my code:
set(t,'ExecutionMode','fixedrate','Period',1,'TimerFcn',[
'cent=(y3dnew(1,:)+y3dnew(5,:))/2;' ,
'xax=(y3dnew(4,:)+y3dnew(5,:))/2 - cent;',
'yax=y3dnew(3,:) - cent;',
'yax=yax/norm(yax);',
'axi=xax/norm(xax);',
'normal=cross(axi,yax);',
'phi=.5;',
'M = [cosd(phi)+axi(1)^2*(1-cosd(phi)) axi(1)*axi(2)*(1-cosd(phi))+axi(3)*sind(phi) axi(1)*axi(3)*(1-cosd(phi))-axi(2)*sind(phi) ; axi(1)*axi(2)*(1-cosd(phi))-axi(3)*sind(phi) cosd(phi)+axi(2)^2*(1-cosd(phi)) axi(2)*axi(3)*(1-cosd(phi))+axi(1)*sind(phi); axi(1)*axi(3)*(1-cosd(phi))+axi(2)*sind(phi) axi(2)*axi(3)*(1-cosd(phi))-axi(1)*sind(phi) cosd(phi)+axi(3)^2*(1-cosd(phi)) ];',
'y3dnew(1,:)=(y3dnew(1,:)-cent)*M+cent;',
'y3dnew(2,:)=(y3dnew(2,:)-cent)*M+cent;',
'y3dnew(3,:)=(y3dnew(3,:)-cent)*M+cent;',
'y3dnew(4,:)=(y3dnew(4,:)-cent)*M+cent;',
'y3dnew(5,:)=(y3dnew(5,:)-cent)*M+cent;',
'trans=[0 -2*norm(cent)*sind(phi) 0]*inv([normal(1) axi(1) yax(1); normal(2) axi(2) yax(2);normal(3) axi(3) yax(3)]);',
'y3dnew(1,:)=y3dnew(1,:)-trans;',
'y3dnew(2,:)=y3dnew(2,:)-trans;',
'y3dnew(3,:)=y3dnew(3,:)-trans;',
'y3dnew(4,:)=y3dnew(4,:)-trans;',
'y3dnew(5,:)=y3dnew(5,:)-trans;',
'cent=(y3dnew(1,:)+y3dnew(5,:))/2;',
'y3dnew(1,:)=(y3dnew(1,:)-cent)*M+cent;',
'y3dnew(2,:)=(y3dnew(2,:)-cent)*M+cent;',
'y3dnew(3,:)=(y3dnew(3,:)-cent)*M+cent;',
'y3dnew(4,:)=(y3dnew(4,:)-cent)*M+cent;',
'y3dnew(5,:)=(y3dnew(5,:)-cent)*M+cent;'],'TasksToExecute',500);
Now I'm getting an error:
Error using ==> vertcat
CAT arguments dimensions are not consistent
Now when I run each line in the TimerFcn separately, there seems to be no error. So, it must be something to do with TimerFcn syntax?
btw, y3dnew is a 5x3 matrix of numbers. And the M in the code is a 3x3 matrix of numbers.
Sorry for the inelegance of the code, but I need help

Answers (1)

TAB
TAB on 27 Jun 2012
Instead of providing such large code in the set() function argument , I will recommend you to write the code as separate callback function in different m-file and provide the file name as argument to set() function.
See here about how to write a timer callback function.
  5 Comments
Jan
Jan on 8 Jul 2012
Edited: Jan on 9 Jul 2012
@TAB: I've removed your flag. I agree with you, that your suggestion is much better than Mohsin's solution. But obviously he has good reasons and forgot to explain them. But you get my vote.
TAB
TAB on 9 Jul 2012
OK, Jan.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!