<< Chapter < Page Chapter >> Page >
This module is part of the collection, A First Course in Electrical and Computer Engineering . The LaTeX source files for this collection were created using an optical character recognition technology, and because of this process there may be more errors than usual. Please contact us if you discover any errors.

If you quit MATLAB now, all the commands you have typed will be lost. This is where the Edit window is useful. If you choose new from the File menu, a new window appears with the title Edit 1 : Untitled . In this window, you should type in all the commands you would like MATLAB to execute atonce. When you are finished typing, you may save the file by choosing save or save as in the file menu and by entering a name for the file. If the edit window is active (that is, if it appears in front), then choose save and go from the file menu to save the file and execute it. If the command window is active,then you can execute the file by entering its name.

Editing Files. To test your understanding of file editing, enter the following commands in a file named myfile:

You do not have to type the % sign and the text that follows it. These are simply comments in a file. They are ignored by the MATLAB interpreter.You should, however, make a habit of adding comments (preceded by %) to your file if you want to be able to understand programs that have been writtenlong ago.

Do not forget to save your file. Such a file is called a script file . It contains MATLAB commands that could have been entered one by one in thecommand window. You have three ways to execute a script file:

  1. with the edit window active, choose save and go from the file menu;
  2. with the command window active, enter the file name; or
  3. with the command window active, choose run script ... from the M-file menu. In this case, a menu pops up to ask you which file you want to execute.

Try each of these three methods in order to get used to their differences. Figure 1 shows the plot that you should get.

Creating Functions. MATLAB puts many commands at your disposal, and you just have to enter their names (with or without arguments) to execute them. Some commands are built in to MATLAB, and others arecontained in files to which you have access (not to modify them, but to see how things are done). You can try to display the contents of a command filein the command window by entering the command type filename. Enter type plot. You should get the message

This is an image of an old apple computer screen, with some matlab code in a window in the background and a graph in a window in the foreground. This is an image of an old apple computer screen, with some matlab code in a window in the background and a graph in a window in the foreground.
A Typical Graph (©Apple Computer, Inc., used with permission.)

This means that the commandis a build-in function and thus cannot be typed by the user (it is compiled with the program). Similarly, try to typethe function file containing the commandby entering the command. You should get type sinh

This is a typical example of a function file . It differs from a script file by the fact that the first line contains the word. What it does is make the commandequivalent to the command. The variableis the input argument (there could be more than one), and y is the output argument (there also could be more than one). The second line contains comments about the function and its arguments. They can spreadto several lines. Display them by typing the command. The third line contains the actual function commands (there could also be several lines). help sinh

As an exercise, enter the function: perp(x)

Evaluateon various complex numbers. Replace the last line by;. Do you get the same result? Why? y = x*j

Note that local variables are just that– local . Only the input and out- put arguments are kept in memory after the function is called and executed.For more on functions and multiple arguments, see the MATLAB manual. In the previous example, the variable j is local. If, before using the function, you use the same variable j , its contents will not be affected by the command. Verify this. perp(z)

Normally, while a file (script or function) is executed, the commands are not displayed on the command window. Just the results are displayed.The commandallows you to view all the instructions. This is useful for debugging and demonstrations. It is turned off by typing. echo off

Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, A first course in electrical and computer engineering. OpenStax CNX. Sep 14, 2009 Download for free at http://cnx.org/content/col10685/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'A first course in electrical and computer engineering' conversation and receive update notifications?

Ask