Info

This question is closed. Reopen it to edit or answer.

How to seperate my function file from my script

1 view (last 30 days)
matthew phelps
matthew phelps on 11 Sep 2019
Closed: MATLAB Answer Bot on 20 Aug 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)

Answers (1)

Cris LaPierre
Cris LaPierre on 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!