This document provides an overview of MATLAB, including:
- MATLAB is a program for numerical computation originally designed for linear algebra problems using matrices. It has since expanded to other types of scientific computations and graphics.
- The main components of the MATLAB interface are the command window, workspace, history, and editor. Help is accessed using commands like help, doc, and demo.
- MATLAB treats all variables as matrices and supports operations on matrices and vectors. Basic math, logical, and relational operators are covered.
- The document discusses plotting, flow control using if/else, switch/case and loops, writing M-files including functions, and saving and loading workspace and data files.
MATLAB stands for Matrix Laboratory. MATLAB was written originally
to provide easy access to matrix software developed by the LINPACK (linear system package) and matlab 2012a manual pdf
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
3 days Hands on workshop on MATLAB/SIMULINK for Engineering Applications:
this workshop aims to make students to aware of MATLAB to do own projects in engineering life with best available technology E-Simulink Softwares and tools.
MATLAB stands for Matrix Laboratory. MATLAB was written originally
to provide easy access to matrix software developed by the LINPACK (linear system package) and matlab 2012a manual pdf
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
3 days Hands on workshop on MATLAB/SIMULINK for Engineering Applications:
this workshop aims to make students to aware of MATLAB to do own projects in engineering life with best available technology E-Simulink Softwares and tools.
interfacing matlab with embedded systemsRaghav Shetty
This Book is all about Interfacing Embedded System with Matlab. This book guides the beginners for creating GUI , Modeling with SimuLink & Interfacing Arduino , Raspberry Pi , BeagleBone with Embedded System. This Book is NOT FOR SALE , Only knowledge base for Open Source Community
This 10 hours class is intended to give students the basis to empirically solve statistical problems. Talk 1 serves as an introduction to the statistical software R, and presents how to calculate basic measures such as mean, variance, correlation and gini index. Talk 2 shows how the central limit theorem and the law of the large numbers work empirically. Talk 3 presents the point estimate, the confidence interval and the hypothesis test for the most important parameters. Talk 4 introduces to the linear regression model and Talk 5 to the bootstrap world. Talk 5 also presents an easy example of a markov chains.
All the talks are supported by script codes, in R language.
MATLAB sessions: Laboratory 1
MAT 275 Laboratory 1
Introduction to MATLAB
MATLAB is a computer software commonly used in both education and industry to solve a wide range
of problems.
This Laboratory provides a brief introduction to MATLAB, and the tools and functions that help
you to work with MATLAB variables and files.
The MATLAB Environment
⋆ To start MATLAB double-click on the MATLAB shortcut icon. The MATLAB desktop will open.
On the left side you will generally find the Current Folder window and on the right the Workspace
and Command History windows. The Command Window is where the MATLAB commands are entered
and executed. Note that windows within the MATLAB desktop can be resized by dragging the separator
bar(s).
If you have never used MATLAB before, we suggest you type demo at the MATLAB prompt. Click
on Getting Started with MATLAB and run the file.
Basics And Help
Commands are entered in the Command Window.
⋆ Basic operations are +, -, *, and /. The sequence
>> a=2; b=3; a+b, a*b
ans =
5
ans =
6
defines variables a and b and assigns values 2 and 3, respectively, then computes the sum a+b and product
ab. Each command ends with , (output is visible) or ; (output is suppressed). The last command on a
line does not require a ,.
⋆ Standard functions can be invoked using their usual mathematical notations. For example
>> theta=pi/5;
>> cos(theta)^2+sin(theta)^2
ans =
1
verifies the trigonometric identity sin2 θ + cos2 θ = 1 for θ = π
5
. A list of elementary math functions can
be obtained by typing
>> help elfun
⋆ To obtain a description of the use of a particular function type help followed by the name of the
function. For example
>> help cosh
gives help on the hyperbolic cosine function.
⋆ To get a list of other groups of MATLAB programs already available enter help:
>> help
c⃝2011 Stefania Tracogna, SoMSS, ASU
MATLAB sessions: Laboratory 1
⋆ Another way to obtain help is through the desktop Help menu, Help > Product Help.
⋆ MATLAB is case-sensitive. For example
>> theta=1e-3, Theta=2e-5, ratio=theta/Theta
theta =
1.0000e-003
Theta =
2.0000e-005
ratio =
50
⋆ The quantities Inf (∞) and NaN (Not a Number) also appear frequently. Compare
>> c=1/0
c =
Inf
with
>> d=0/0
d =
NaN
Plotting with MATLAB
⋆ To plot a function you have to create two arrays (vectors): one containing the abscissae, the other the
corresponding function values. Both arrays should have the same length. For example, consider plotting
the function
y = f(x) =
x2 − sin(πx) + ex
x − 1
for 0 ≤ x ≤ 2. First choose a sample of x values in this interval:
>> x=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1, ...
1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2]
x =
Columns 1 through 7
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000
Columns 8 through 14
0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000
Columns 15 through 21
1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000
Note that an ellipsis ... was used to continue a command too long to fit in a sing ...
Antarctica- Icy wilderness of extremes and wondertahreemzahra82
In this presentation, we delve into the captivating realm of Antarctica, Earth's southernmost continent. This icy wilderness stands as a testament to extremes, with record-breaking cold temperatures and vast expanses of pristine ice. Antarctica's landscape is dominated by towering glaciers, colossal icebergs, and expansive ice shelves. Yet, amidst this frozen expanse, a rich tapestry of unique wildlife thrives, including penguins, seals, and seabirds, all finely attuned to survive in this harsh environment. Beyond its natural wonders, Antarctica also serves as a vital hub for scientific exploration, providing invaluable insights into climate change and the Earth's history
4 DAYS MASAI MARA WILDEBEEST MIGRATION SAFARI TOUR PACKAGE KENYABush Troop Safari
Join our 4-day Masai Mara Wildebeest Migration Safari in Kenya. Witness the incredible wildebeest migration, enjoy exciting game drives, and stay in comfortable lodges. Get up close and personal with one of nature's most amazing exhibits! Book Your Safari Today at - https://bushtroop-safaris.com/
interfacing matlab with embedded systemsRaghav Shetty
This Book is all about Interfacing Embedded System with Matlab. This book guides the beginners for creating GUI , Modeling with SimuLink & Interfacing Arduino , Raspberry Pi , BeagleBone with Embedded System. This Book is NOT FOR SALE , Only knowledge base for Open Source Community
This 10 hours class is intended to give students the basis to empirically solve statistical problems. Talk 1 serves as an introduction to the statistical software R, and presents how to calculate basic measures such as mean, variance, correlation and gini index. Talk 2 shows how the central limit theorem and the law of the large numbers work empirically. Talk 3 presents the point estimate, the confidence interval and the hypothesis test for the most important parameters. Talk 4 introduces to the linear regression model and Talk 5 to the bootstrap world. Talk 5 also presents an easy example of a markov chains.
All the talks are supported by script codes, in R language.
MATLAB sessions: Laboratory 1
MAT 275 Laboratory 1
Introduction to MATLAB
MATLAB is a computer software commonly used in both education and industry to solve a wide range
of problems.
This Laboratory provides a brief introduction to MATLAB, and the tools and functions that help
you to work with MATLAB variables and files.
The MATLAB Environment
⋆ To start MATLAB double-click on the MATLAB shortcut icon. The MATLAB desktop will open.
On the left side you will generally find the Current Folder window and on the right the Workspace
and Command History windows. The Command Window is where the MATLAB commands are entered
and executed. Note that windows within the MATLAB desktop can be resized by dragging the separator
bar(s).
If you have never used MATLAB before, we suggest you type demo at the MATLAB prompt. Click
on Getting Started with MATLAB and run the file.
Basics And Help
Commands are entered in the Command Window.
⋆ Basic operations are +, -, *, and /. The sequence
>> a=2; b=3; a+b, a*b
ans =
5
ans =
6
defines variables a and b and assigns values 2 and 3, respectively, then computes the sum a+b and product
ab. Each command ends with , (output is visible) or ; (output is suppressed). The last command on a
line does not require a ,.
⋆ Standard functions can be invoked using their usual mathematical notations. For example
>> theta=pi/5;
>> cos(theta)^2+sin(theta)^2
ans =
1
verifies the trigonometric identity sin2 θ + cos2 θ = 1 for θ = π
5
. A list of elementary math functions can
be obtained by typing
>> help elfun
⋆ To obtain a description of the use of a particular function type help followed by the name of the
function. For example
>> help cosh
gives help on the hyperbolic cosine function.
⋆ To get a list of other groups of MATLAB programs already available enter help:
>> help
c⃝2011 Stefania Tracogna, SoMSS, ASU
MATLAB sessions: Laboratory 1
⋆ Another way to obtain help is through the desktop Help menu, Help > Product Help.
⋆ MATLAB is case-sensitive. For example
>> theta=1e-3, Theta=2e-5, ratio=theta/Theta
theta =
1.0000e-003
Theta =
2.0000e-005
ratio =
50
⋆ The quantities Inf (∞) and NaN (Not a Number) also appear frequently. Compare
>> c=1/0
c =
Inf
with
>> d=0/0
d =
NaN
Plotting with MATLAB
⋆ To plot a function you have to create two arrays (vectors): one containing the abscissae, the other the
corresponding function values. Both arrays should have the same length. For example, consider plotting
the function
y = f(x) =
x2 − sin(πx) + ex
x − 1
for 0 ≤ x ≤ 2. First choose a sample of x values in this interval:
>> x=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1, ...
1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2]
x =
Columns 1 through 7
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000
Columns 8 through 14
0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000
Columns 15 through 21
1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000
Note that an ellipsis ... was used to continue a command too long to fit in a sing ...
Antarctica- Icy wilderness of extremes and wondertahreemzahra82
In this presentation, we delve into the captivating realm of Antarctica, Earth's southernmost continent. This icy wilderness stands as a testament to extremes, with record-breaking cold temperatures and vast expanses of pristine ice. Antarctica's landscape is dominated by towering glaciers, colossal icebergs, and expansive ice shelves. Yet, amidst this frozen expanse, a rich tapestry of unique wildlife thrives, including penguins, seals, and seabirds, all finely attuned to survive in this harsh environment. Beyond its natural wonders, Antarctica also serves as a vital hub for scientific exploration, providing invaluable insights into climate change and the Earth's history
4 DAYS MASAI MARA WILDEBEEST MIGRATION SAFARI TOUR PACKAGE KENYABush Troop Safari
Join our 4-day Masai Mara Wildebeest Migration Safari in Kenya. Witness the incredible wildebeest migration, enjoy exciting game drives, and stay in comfortable lodges. Get up close and personal with one of nature's most amazing exhibits! Book Your Safari Today at - https://bushtroop-safaris.com/
Discover the wonders of the Wenatchee River with a variety of river tours in Monitor, WA. Whether you're seeking thrilling whitewater rafting, peaceful kayaking, family-friendly float trips, or scenic sunset cruises, there's something for everyone. Enjoy fishing, wildlife spotting, bird watching, and more in this beautiful natural setting, perfect for outdoor enthusiasts and families alike.
Discover Palmer, Puerto Rico, through an immersive cultural tour that unveils its rich history and vibrant traditions. Experience lively festivals, savor authentic cuisine, and explore local markets. Visit historical landmarks, museums, and stunning colonial architecture. Engage with friendly locals, enjoy live music, and hike scenic nature trails, all while participating in cultural workshops and discovering unique artisan crafts.
How To Change Name On Volaris Ticket.pdfnamechange763
How to change name on Volaris ticket? This is one of the most common questions asked by travelers flying with Volaris Airlines. The mentioned details can help you with your name rectification on the airline ticket. If you are still facing difficulties call the consolidation desk at +1-800-865-1848.
During the coldest months, Italy transforms into a winter wonderland, providing visitors with a very unique experience. From the Settimana Bianca ski event to the lively Carnevale celebrations, Italy's winter festivities provide something for everyone. Enjoy hot cocoa, eat hearty comfort foods, and buy during winter deals. Explore the country's rich cultural past by participating in Settimana Bianca, and Carnevale, sipping hot chocolate, shopping during winter deals, and indulging in winter comfort foods. Visit our website https://timeforsicily.com/ for more information.
LUXURY TRAVEL THE ULTIMATE TOKYO EXPERIENCE FROM SINGAPORE.pdfDiper Tour
Get off on the most luxurious Tokyo itinerary from Singapore. Experience Tokyo’s sophisticated modernism and rich tradition with first-class travel, sumptuous lodging, fine food, and special tours. Savor the finest that this energetic city has to offer for an experience that will never be forgotten.
Its running cost is among the diverse vital aspects you must consider before buying an electric scooter. Calculate the cost of getting e-scooter charge for your regular usage to calculate its economic efficiency, similar to people who investigate the mileage of petrol or diesel-driven scooters.
The Power of a Glamping Go-To-Market Accelerator Plan.pptxRezStream
Unlock the secrets to success with our comprehensive 8-Step Glamping Accelerator Go-To-Market Plan! Watch our FREE webinar, where you'll receive expert guidance and invaluable insights on every aspect of launching and growing your glamping business.
How To Talk To a Live Person at American Airlinesflyn goo
This page by FlynGoo can become your ultimate guide to connecting with a live person at American Airlines. Have you ever felt lost in the automated maze of customer service menus? FlynGoo is here to rescue you from endless phone trees and automated responses. With just a click or a call to a specific number, we ensure you get the human touch you deserve. No more frustration, no more waiting on hold - we simplify the process, making your travel experience smoother and more enjoyable.
MC INTERNATIONALS | TRAVEL COMPANY IN JHANGAshBhatt4
Experience the world with MC Internationals travel and tourism. From foreign getways to cultural concentration, we tailor unforgettable journeys for every traveler. Let us turn your dream into reality and create lasting memories. Explore with us today. #TRAVEL,COMPANY #BEST,TRAVEL,COMPANY #VISIT,VISA #EMPLOYMENT,VISA #STUDY,VISA #HAJJ,AND,UMRAH
The Cherry Blossom season in Hunza begins in the second week of March and lasts until the end of April, varying with altitude. During this enchanting period, tourists from around the world flock to Hunza Valley to witness its transformation into a vibrant tapestry of white, pink, and green. The valley comes alive with cherry blossoms, creating a picturesque and mesmerizing landscape that captivates visitors.
About the Company:
The Cherry Blossom season in Hunza starts in the second week of March and extends until the end of April, depending on the altitude. During this enchanting period, tourists from around the globe travel to Hunza Valley to witness its transformation into a vibrant tapestry of white, pink, and green. The valley comes alive with cherry blossoms, creating a picturesque and mesmerizing landscape that captivates all who visit. For the best experience, join Hunza Adventure Tours, the top tour company in Pakistan, and immerse yourself in this breathtaking seasonal spectacle.
BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. BTW UK Visa Application Process, Uk Visa complete guide, Uk Visa fees, requirements and application process. Know all about uk visa and best way to apply for the uk visa. Get to know about the requirements that allows you for the faster visa appliaction. Get information in this PDF and simplyfy your visa process.
London Country Tours, the foremost travel partner offers customized Stonehenge tours from London coming with private tour guides and direct access to the inner circles. Visit: https://www.londoncountrytours.co.uk/tour/tours-to-stonehenge-oxford/
Exploring Montreal's Artistic Heritage Top Art Galleries and Museums to VisitSpade & Palacio Tours
Montreal boasts a vibrant artistic heritage, showcased in its top art galleries and museums. From the expansive collections at the Montreal Museum of Fine Arts to the cutting-edge exhibits at the Musée d'art contemporain, discover the city's rich cultural landscape. Experience dynamic street art, indigenous works, and contemporary pieces, reflecting Montreal's diverse and innovative art scene.
2. MATLAB
MATLAB is a program for doing numerical computation.
It was originally designed for solving linear algebra type
problems using matrices. It’s name is derived from
MATrix LABoratory.
MATLAB has since been expanded and now has built-
in functions for solving problems requiring data analysis,
signal processing, optimization, and several other types
of scientific computations. It also contains functions for
2-D and 3-D graphics and animation.
3. MATLAB
When you first open MATLAB, notice:
1.The command window is where you'll give
MATLAB its input and view its output.
2.The workspace shows you all of your current
working variables and other objects.
3.The history shows you all commands you used
in CW.
4.The Editor for MATLAB scripts (M-files) . To
save & run the m-file type 'F5'. To open the
editor with a new or old m-file use the command
open file_name
4. MATLAB help
For help, command description etc use F1 or following
commands:
help command_name
helpwin command_name
doc command_name
helpdesk command_name
demo command_name
lookfor keyword (search unknown command)
http://www.mathworks.com/support/
For example when running “help sin” one get
SIN Sine of argument in radians.
SIN(X) is the sine of the elements of X.
See also ASIN, SIND.
Overloaded functions
Reference page in Help browser doc sin
5. Some Useful commands
what List all m-files in current directory
dir/ls List all files in current directory
type test Display test.m in command window
delete test Delete test.m
cd/chdir Change directory
pwd Show current directory
which test Display directory path to ‘closest’ test.m
who List known variables
whos List known variables plus their size
clear Clear variables from workspace
clc Clear the command window
6. MATLAB & Matrices
MATLAB treats all variables as matrices. For our
purposes a matrix can be thought of as an array, in fact,
that is how it is stored.
Vectors are special forms of matrices and contain only
one row OR one column.
Scalars are matrices with only one row AND one column
7. Variable Names
Variable names ARE case sensitive
Variable names can contain up to 63 characters (as of MATLAB 6.5
and newer). One can use namelengthmax command to
verify it.
Variable names must start with a letter followed by letters, digits,
and underscores.
MATLAB variables are defined by assignment. There is no need to
declare in advance the variables that we want to use or their type.
Example
x=1; % Define the scalar variable x
y=[1 2 3] % row vector
z=[1;2;3] % column vector
A=[1 2 3;4 5 6;7 8 9] % 3x3 matrix
whos % List of the variables defined
Note: terminate statement with semicolon (;) to suppress output.
8. Special Variables
ans Default variable name for results
pi Value of π
eps Smallest incremental number
inf Infinity
NaN Not a number e.g. 0/0
i,j,1i,1j imaginary unit i, i.e. square root of -1
realmin The smallest usable positive realnumber
realmax The largest usable positive real number
SpecialVars.m
9. Other symbols
>> prompt
. . . continue statement on next line
, separate statements and data
% start comment which ends at end of line
; (1) suppress output
(2) used as a row separator in a matrix
: specify range
10. Relational Operators
MATLAB supports six relational operators.
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equal To ==
Not Equal To ~=
11. Math & Assignment Operators
Power ^ or .^ a^b or a.^b
Multiplication * or .* a*b or a.*b
Division / or ./ a/b or a./b
or or . ba or b.a
NOTE: 56/8 = 856
- (unary) + (unary)
Addition + a + b
Subtraction - a - b
Assignment = a = b (assign b to a)
Operators.m
12. MATLAB Logical Operators
MATLAB supports five logical operators.
not/~ element wise/scalar logical NOT
and/& element wise logical AND
or / | element wise logical OR
&& logical (short-circuit) AND
|| logical (short-circuit) AND
13. Logical Functions
MATLAB also supports some logical functions.
xor (a, b) exclusive or
any(x) returns 1 if any element of x is nonzero
all(x) returns 1 if all elements of x are nonzero
isnan(x) returns 1 at each NaN in x
isinf(x) returns 1 at each infinity in x
finite(x) returns 1 at each finite value in x
find(x) find indices and values of non zero
elements
14. Some Matrix functions
zeros(rows, cols) – create zero matrix
rand(rows, cols) – generate random matrix
ones(rows, cols) – matrix with 1 in all entries
eye (rows, cols) – identity matrix
sub2ind, ind2sub indices manipulation
15. Extracting a Sub-Matrix
A portion of a matrix can be extracted and stored in a
smaller matrix by specifying the names of both matrices
and the rows and columns to extract. The syntax is:
sub_matrix = matrix ( r1 : rn , c1 : cn ) ;
sub_matrix = matrix ( r1 : rn , : ) ;
sub_matrix = matrix ( : , c1 : cn ) ;
sub_matrix = matrix ( r1 : dr : rn , c1 : dc : cn ) ;
where r1 and rn specify the beginning and ending rows
and c1 and cn specify the beginning and ending
columns to be extracted to make the new matrix.
The terms dr and dc define spacing different than one.
matrix.m
16. “Continuous” functions
Numerically, we cannot represent a general continuous function
(x,f(x)) because it requires handling infinite data (for each point in
the range, we need to keep f(x)). Instead, we represent a function by
its values at a finite number of data points (x_i,f(x_i)), where the
series of points {x_i} is typically referred to as the sampling points or
the grid points. Accordingly, the "continuous" functions in Matlab
accepts a vector of point {x_i} and return a vector of values {f(x_i)}.
Some functions
sqrt
log
cos/acos/sin/asin etc
exp - exponential
abs
sign
norm
sum
prod - product
17. Plotting
MATLAB will plot one vector vs. another. The first one will be
treated as the abscissa (or x) vector and the second as the ordinate
(or y) vector. The vectors have to be the same length.
MATLAB will also plot a vector vs. its own index. The index will be
treated as the abscissa vector. Given a vector “time” and a vector
“dist” we could say:
>> plot (time, dist) % plotting versus time
>> plot (time + i*dist) % plotting versus time
>> plot (dist) % plotting versus index
Sometime we want to see it with different colorline stile
>> plot (time, dist, line_characteristics)
And sometime we want to plot few functions in graphs
>> plot(…), hold, plot(…)
>> plot(t,d1,l_c1, t,d2, l_c2)
To split page to several axes check use
>> subplot (rows, cols, place)
18.
19. Plotting
There are commands in MATLAB to "annotate" a plot to put on axis
labels, titles, and legends. For example:
To put a label on the axes we would use:
>> xlabel ('X-axis label')
>> ylabel ('Y-axis label')
To put a title on the plot, we would use:
>> title ('Title of my plot')
To distinct between function in the graph use:
>> legend(legend_1, legend_2)
plotting.m
20. Flow control (condition)
An if - elseif - else structure. (Note that elseif is one word)
if expression1
statements1
elseif expression2
statements2
else
statements3
end
An switch-case structure
switch switch_expr
case case_expr
statement, ..., statement
case {case_expr1, case_expr2, case_expr3, ...}
statement, ..., statement
otherwise
statement, ..., statement
end
21. Flow control (loops)
A for loop in MATLAB
for ind = 1:100
b(ind)=sin(ind/10)
end
Alternative (Most of the loops can be avoided!!!):
x=0.1:0.1:10;
b=sin(x);
A while loop in
while x <= 10
% execute these commands
end
22. M-Files
An M-file might be used as a script, i.e. file consist set
of statements
In additional, one use M-files to write function, in this
case the file starts with function definition like:
function y = f(x)
function [u,v] = f(x,y,z)
File name and the name of function in the file are
usually identical, however while they are different,
MATLAB use file name to call function.
If you add additional function in same M-file, it
considered sub-function and might be called from inside
the M-file only. Only the first function might be called
from outside.
23. Saving Results
We can save all our results for future reference .
The command
diary ‘FileName'
saves all output to command window into the FileName.txt file until
this option is turned off by the command
diary off
The following commands save & load the entire workspace
into the file 'MyMatFile.mat'
save 'MyMatFile'
load 'MyMatFile'
save 'x.mat' x % save a specific variable
saving in ASCII format:
x = (-1:0.4:1)' ; y = sin(x*pi)
var = [x y] % double-column
save 'my_sin.dat' -ASCII -double var %Save in 16-digit ASCII format