Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to seperate my function file from my script

1 次查看(过去 30 天)
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)

回答(1 个)

Cris LaPierre
Cris LaPierre 2019-9-11
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