Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to seperate my function file from my script

조회 수: 1 (최근 30일)
matthew phelps
matthew phelps 2019년 9월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
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