hello, Can someone please help write the following algorithm as a Matlab Function for Simulink? i am having trouble with the else statement and time increments. Thanks!

1 次查看(过去 30 天)
  3 个评论
Muhammad Rameez Rashid
Thank you for your comment, i tried to model it in simulink but i couldnt model branched signals using the Merge block. i tried using signal conversion blocks as well but it did not work.
i tried using a Matlab function instead but i am stuck at using the else statement and defining simulation time increments, since it takes the Target point from the previous time step
Muhammad Rameez Rashid
I am not very proficient with matlab coding but this is the example i am working on. Any help, suggestions or guidance would be really helpful.
T_p = [30*pi/180; 30*pi/180]'; % + reference point
phi_p = T_p(1); %phi +
T_n = [-30*pi/180; 30*pi/180]'; %- reference point
phi_n = T_n(1); % phi -
tk = 0.1; %time step
t= 0:tk:10; %simulation time
phi = 50*cos(t);
theta = 40+30*sin(2*t);
%plot(phi,theta)
for k = 0:t
if phi > phi_p
Ta = Tn; %set target point
elseif phi < phi_n
Ta = Tp; %set target point
else
%i need to keep the values from the previous time step if else
%statement is executed
end
end

请先登录,再进行评论。

回答(1 个)

AMIT POTE
AMIT POTE 2022-7-3
You can go through the following documentation to understand writing if-else statements in MATLAB

类别

Help CenterFile Exchange 中查找有关 Model Verification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by