Saturday, 31 May 2014

Matlab basic commands


Command
Description
exit
Terminate MATLAB
finish
MATLAB termination M-file
matlabrc
MATLAB startup M-file for
single-user systems or system
administrators
prefdir
Directory containing preferences,
history, and layout files
preferences
Open Preferences dialog box for
MATLAB and related products
quit
Terminate MATLAB
clc
Clear Command Window
commandhistory
Open Command History window, or
select it if already open
commandwindow
Open Command Window, or select it
if already open
diary
Save session to file
matlabcolon (matlab:)
Run specified function via hyperlink
perl
Call Perl script using appropriate
operating system executable
unix
Execute UNIX command and return
result
demo
Access product demos via Help
browser
echodemo
Run M-file demo step-by-step in
Command Window
help
Help for MATLAB functions in
Command Window
helpbrowser
Open Help browser to access all
online documentation and demos
helpwin
Provide access to M-file help for all
functions


Workspace

assignin
Assign value to variable in specified
workspace
clear
Remove items from workspace,
freeing up system memory
evalin
Execute MATLAB expression in
specified workspace
exist
Check existence of variable, function,
directory, or Java class
openvar
Open workspace variable in Array
Editor or other tool for graphical
editing
which
Locate functions and files
workspace
Open Workspace browser to manage
workspace
uiimport
Open Import Wizard to import data



sparse
Create sparse matrix
zeros
Create array of all zeros


Publishing

grabcode
MATLAB code from M-files
published to HTML
notebook
Open M-book in Microsoft Word
(Windows)
publish
Publish M-file containing cells,
saving output to file of specified type

loops and dairy files in matlab

Loops
A loop specifies that a command or group of commands should be repeated several times
The easiest way to create a loop is to use a for statement.


f = 1;
for n = 2:10
f = f*n;
end
f

use a semicolon to suppress intermediate output within the loop
To see the final output, we then needed to type f after the end of the loop.


Diary Files

The first diary command causes all subsequent input to and output from the Command Window to be copied into the specified file
By using delete at the beginning of the M-file, you ensure that the file only contains the output of the current script.If you omit the delete command, then the diary command will add any new output to the end of an existing file and can end up containing the results of several runs of
the M-file



Mention  at the starting

delete task1.txt
diary task1.txt
echo on

The script M-file should then end with the commands
echo off
diary off


You can also get extraneous output in a diary file if you type CTRL+C to halt a script containing a diary command. If this happens, you should type diary off in the Command Window before running the script again.

M-files and structuring M-files in matlab


M-Files
the Command Window and its history mechanism are insufficient in some cases
A much better approach is to create an M-file. There are two different kinds of M-files


1. script M-files
2. function M-files.
M-files are ordinary text files containing MATLAB commands where you can create and modify them.
you can use the built-in Editor/Debugger

Echoing Commands
echo:
the commands in a script M-file will not automatically be displayed in the Command Window. If you want the commands to be displayed along with the results, use echo

echo on
format long
x = [0.1, 0.01, 0.001];
y = sin(x)./x
echo off

Adding Comments.
to get the explanation of the command used

echo on
% Turn on 15 digit display
format long
x = [0.1, 0.01, 0.001];
y = sin(x)./x
% These values illustrate the fact that the limit of
% sin(x)/x as x approaches 0 is 1.
echo off

Structuring Script M-Files.
the script should be self-contained, unaffected by other variables that you might have defined elsewhere in the MATLAB session

clear all: you can type the line clear all at the beginning of the script, to ensure that previous definitions of variables do not affect the results.

close all command at the beginning of a script M-file that creates graphics, to close all graphics windows and start with a clean slate

% Remove old variable definitions
clear all
% Remove old graphics windows
close all
% Display the command lines in the command window
echo on
% Turn on 15 digit display
format long



Fine-Tuning Your M-Files
  1. Include clear all and close all at the beginning of the M-file.
  2. Use echo on early in your M-file so that you can see “cause” as well as “effect”.
  3. If you are producing graphics, use hold on and hold off carefully.
  4. In general, you should put a pause statement after each hold off.
  5. Otherwise, the next graphics command will obliterate the current one, and you won’t see it.
  6. Do not include bare print statements in your M-files. Instead, print to a file.
  7. Make liberal use of pause.
  8. Finally, remember that you can stop a running M-file by typing CTRL+C.This is useful if, at a pause or input statement, you realize that you want to stop execution completely.

 

how to get started on matlab basics


Online Help


You can access the online help in one of several ways. Typing help at the command prompt will reveal a long list of topics

help general :see a long list of “general purpose” MATLAB commands
help solve: to learn about the command solve
helpwin or helpdesk at the command prompt to access the online help
syms to declare the variables
syms x y
(x - y)*(x - y)^2
expand(ans)
factor(ans)

Symbolic Expressions
simplify, which you can sometimes use to express a formula as simply as possible
simplify((x^3 - y^3)/(x - y))

arithmetic with symbolic expressions.

cos(pi/2)
cos(sym(’pi/2’)) - cosine of the symbolic representation of π/2

use of sym
create a string consisting of the characters pi/2 and prevent MATLAB from evaluating pi/2 as a floating point number. The command sym converts the string to a symbolic expression


to calculate the values of sin(0.1)/0.1, sin(0.01)/0.01, and sin(0.001)/0.001
x = [0.1, 0.01, 0.001];
y = sin(x)./x

 

What is image processing and matlab



An image is a 2-D function f(x,y) where x and y are spatial coordinates and the amplitude f at any pair of co-ordinates (x,y) is called the intensity values of the image at that point. Digital image  is composed of a finite number of elements each of which has a particular location and value. These elements are called as image elements, pels, pixels. Pixel is used to denote the elements of a digital image

Matlab is a high-performance language for technical computing.  It integrates computation, visualization, and programming in a easy environment. It is an interaction matrix laboratory. ve system  whose data element is an array that doesn’t require dimensions

The name MATLAB stands for matrix laboratory. Matlab is standard computational tool for introductory and advanced courses in mathematics and engineering. The image processing toolbox is a collection of MATLAB functions called m-files that extend the capability of the MATLAB environment to image processing problems

Matlab Windows

the start of Matlab it shows four different windows namely ‘command window’, ‘command history’, ‘Workspace’, ‘Current folder’.

1.      Command Window: This is the pace where the commands are to be written.
2.     Command History: This is the space where the executed commands are stored for future reference or use.
3.      Workspace: This window contains all the variables generated during the work for reference, so it is always advised to choose the name of the variables in relation to the work.

4.      Current Folder: This window shows the current directory in which you are working or the place where the current files will be stored.

MATLAB:

is a high-performance, high-level language.
stands for Matrix Laboratory
can be used as a fancy calculator
allows you to easily work with entire matrices rather than one number at a time
is useful for anything that requires matrix and vector manipulations such as:
Mathematical, scientific, engineering, statistical and financial problems
Anything that requires plotting/visualizing and analyzing data
comes with a basic set of tools for visualizing data and for performing calculations on matrices and vectors
For specific technologies, MATLAB provides toolboxes, which add to the basic MATLAB functionality. We have the Image Processing Toolbox. Some other toolboxes include:

  • Statistics Toolbox
  • Neural Network Toolbox
  • Fuzzy Logic Toolbox
  • Signal Processing Toolbox
  • Wavelet Toolbox
  • Financial Toolbox
  • Bioinformatics Toolbox
  • Database Toolbox