Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

TimerFcn, Error using VertCat?

조회 수: 2 (최근 30일)
Mohsin
Mohsin 2012년 6월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

TAB
TAB 2012년 6월 27일
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
Jan
Jan 2012년 7월 8일
편집: Jan 2012년 7월 9일
@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 2012년 7월 9일
OK, Jan.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by