0% found this document useful (0 votes)
7 views3 pages

Experiment 2

Signals & System Experiment-2 Solution.

Uploaded by

WAQAR BHATTI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Experiment 2

Signals & System Experiment-2 Solution.

Uploaded by

WAQAR BHATTI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Hafiz Waqar Ahmad Bhatti

Reg. No: L1F20BSEE0053 (EB)

Experiment No. 2:
M-FILE, FUNCTIONS AND FUNCTION FILES

Introduction
MATLAB is a programming language, as well as an interactive computational environment. Files that include
code in the MATLAB language are called M-files.

There are two types of M-files: script files and function files.

A script file consists of a sequence of normal MATLAB statements. If the file has the filename, say, rotate.m,
then the MATLAB command rotate will cause the statements in the file to be executed. Variables in a script file
are global and will change the value of variables of the same name in the environment of the current MATLAB
session.

Function files provide extensibility to MATLAB. We can create new functions specific to your problem which will
then have the same status as other MATLAB functions. Variables in a function file are by default local. However,
we can declare a variable to be global if you wish.

Objective
1. To make,save and call M-file.
2. To define and call a function in M-file.
3. Learn to access local and global variables.

Design and Caluclations


Sample Problem

C=46;
[K] = CtoK(C)

K = 319

Issues
We did not face any issues during the experiment.

Conlcusion
• We can make functions in the M-file and use them in our code to by calling the functions.
• We can also make user defined functions to perform our respective tasks.

1
Applications
An m-file, or script file, is a simple text file where you can place MATLAB commands. When the file is
run, MATLAB reads the commands and executes them exactly as it would if you had typed each command
sequentially at the MATLAB prompt. All m-file names must end with the extension '.

Lab Assignment Solution


Problem-1

r=30;
R=45;
V_silo=120000;
[h_silo,sa] = Silo(R,r,V_silo)

h_silo = 39.6885
sa = 9.6411e+03

Problem-2(a)

x=6;
[y] = problem1(x)

y = 4.5401

Problem-2(b)

x=1;
[y] = problem1(x)

y = 0.7071

x=3;
[y] = problem1(x)

y = 3.0307

x=5;
[y] = problem1(x)

y = 4.1347

x=7;
[y] = problem1(x)

y = 4.8971

x=9;
[y] = problem1(x)

2
y = 5.5197

x=11;
[y] = problem1(x)

y = 6.0638

Problem-3

F1='Please Enter the Temprature in Fahrenheit : ';


Fah1=input(F1);
F2='Please Enter the Temprature in Fahrenheit : ';
Fah2=input(F2);
del_T=Cel2-Cel1;
alpha=23.1*10^-6;
L=4.5;
[Cel1,Cel2,del_L] = FtoC(Fah1,Fah2,alpha,L,del_T)

Cel1 = 4.4444
Cel2 = 33.3333
del_L = 0.0030

Problem-4 (a)

h= 'Please Enter the height in inches : ';


in=input(h);
w='Please Enter the weight in pounds : ';
lb=input(w);
[cm,kg] = STtoSI(in,lb)

cm = 172.7200
kg = 79.2750

Problem-4 (b)

in=71;
lb=200;
[cm,kg] = STtoSI(in,lb)

cm = 180.3400
kg = 90.6000

You might also like