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 view (last 30 days)
  3 Comments
Muhammad Rameez Rashid
Muhammad Rameez Rashid on 3 Jul 2022
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
Muhammad Rameez Rashid on 3 Jul 2022
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

Sign in to comment.

Answers (1)

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

Products

Community Treasure Hunt

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

Start Hunting!