TimerFcn, Error using VertCat?

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

I tried that, but get some errors I can't seem to bypass. This seems like the best way to do so.
I'd just like to know if there's a syntax error in how I've specified the TimerFcn. I don't normally work with timers, and hence, am quite probably wrong
Never mind. All I had to do was add "..." after every ",". Thanks anyway
No, using a large string as callback is definitely a very bad choice. Don't do it, but write it as a function. If errors occur, fix them.
Remember that the timer function is processed in the base workspace. Therefore the string callback is very susceptible and impossible to debug.
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.
OK, Jan.

This question is closed.

Tags

Asked:

on 27 Jun 2012

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!