Matlab: Execute the loop until the specified conditions are met -


recently came across simple issues not solve on own. have simulink model uses matlab function calculations inside model. idea @ specified moment of time need change voltage of electric drive. , need change until rotor’s position reaches specified value. instance:

 if control_signal == 1;  (command start execution);      while angle ~= 180 \\ desired angle 180;   control voltage = 5 - 0.1 (5v initial value, while increment of           voltage change 0.1)   end   end 

so technically thinking happen, cycle executed until angle of 180 reached, @ value of control voltage (for instance 4.6). when running code, simulink can’t execute model. without warning or errors, simulation freezes @ stage (when main condition kicks in). looks can’t process further when cycle’s execution starts. can me code? because described behaviour of model during simulation caused above mentioned code.

thank in advance.

my guess convert value of angle expressed in radians degrees, , calculate angle beforehand using trigonometry functions - never reach precisely 180 degrees. should choose epsilon such 180 - epsilon close enough 180 application , use value loop condition.

also, based on description of problem trying solve, sounds want check whether angle not greater 180, not if equals 180.

also, incrementing voltage incorrectly. everytime enter loop, control_voltage variable equals 5 - 0.1, means it's constant , equal 4.9 no matter how many times run loop. correct way:

control_voltage = 5; % initial value if control_signal == 1;  (command start execution);     while angle ~= (180 - epsilon) % epsilon of choice         control_voltage = control_voltage - 0.1; % it's smaller 0.1 every time loop run     end end 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -