MATLAB Answers

0

How to seperate my function file from my script

Asked by matthew phelps on 11 Sep 2019
Latest activity Answered by Cris LaPierre
on 11 Sep 2019
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)

  0 Comments

Sign in to comment.

1 Answer

Answer by Cris LaPierre
on 11 Sep 2019

There are several examples given on this page.

  0 Comments

Sign in to comment.