Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to seperate my function file from my script

1 vue (au cours des 30 derniers jours)
matthew phelps
matthew phelps le 11 Sep 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Defining Functions in MATLAB: Devices that limit the output voltage to a maximum allowed value A are called clippers. Mathematically, we can represent a clipper by a piecewise function.
I have a working script file which performs the neccessary operations, but I would like to make two files. The logic part with the if statement through the end needs to be in a function file. When performed with the script below, it should have the same output.
Basically, I want to seperate a function file from a script file. I would like to seperate my if statement into a function file which utilizes this script.
This is the script below:
w1=2*pi;% Varaible 1
f1=w1/(2*pi); %frequency of f1
T1 =1/f1;% Period of fxn 1
A=3;
T = T1;
step= T/50; %determines stepsize from smallest period
t = 0:step:4;
v = 5*cos(w1*t);
vclip = v;
for i=1:length(v)
if v(i)>A
vclip(i)=A;
end
if v(i)<-A
vclip(i)=-A;
end
end
plot(t,vclip)

Réponses (1)

Cris LaPierre
Cris LaPierre le 11 Sep 2019
There are several examples given on this page.

Community Treasure Hunt

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

Start Hunting!

Translated by