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
댓글 수: 0
답변 (1개)
TAB
2012년 6월 27일
1 개 추천
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.
댓글 수: 5
Mohsin
2012년 6월 27일
Mohsin
2012년 6월 27일
Jan
2012년 6월 27일
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.
TAB
2012년 7월 9일
OK, Jan.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!