Effacer les filtres
Effacer les filtres

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 vue (au cours des 30 derniers jours)
  3 commentaires
Muhammad Rameez Rashid
Muhammad Rameez Rashid le 3 Juil 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 le 3 Juil 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

Connectez-vous pour commenter.

Réponses (1)

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

Catégories

En savoir plus sur Signal Generation, Manipulation, and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by