Wednesday 6 November 2013

MATLAB BASIC FUNDAMENTALS- PART 1

Read the following book to get more knowledge in MATLAB.

Creating Variables :
Assigning values to variables :

x = 5.71;

A = [1 2 3; 4 5 6; 7 8 9];

Create Numeric Arrays :

Creating a single element, 1-by-1 arrays

A = 100;

Creating a matrix(a two-dimensional, rectangular array of numbers)

B = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6]

columns - seperated by comma , rows - seperated by semicolon

Creating a Vector ( 1-by-norn-by-1 array)

C = [1, 2, 3]

D = [10; 20; 30]

Using Ellipses (...) :

Continue Long Statements on Multiple Lines

s = 1 - 1/2 + 1/3 - 1/4 + 1/5 ...
- 1/6 + 1/7 - 1/8 + 1/9;

Calling a MATLAB Functions :

Inputs to functions enclosed in parentheses:

max(A)

Multiple inputs separated by commas:

max(A,B)

Storing output from a function to a variable:

maxA = max(A)

Enclosing multiple outputs in square brackets:

[maxA, location] = max(A)

Displaying a text:

disp('hello world')

Ignoring Functions Outputs :


Ignore the first output using a tilde (~).

[~,name,ext] = fileparts(helpFile);

Exist or Which Function 


Check whether a name is already in use with the exist or which function. 

exist checkname
ans = 0

exist returns 0 if there are no existing variables or functions

Case and Space Sensitivity :

MATLAB code is case sensitive and insensitive to blank spaces except when defining arrays.

Function Syntax :

[output1, ..., outputM] = functionName(input1, ..., inputN)

Command Syntax :

functionName input1 ... inputN

Errors in MATLAB Function Calling :

Error: <functionName> was previously used as a variable, conflicting with its use here as the name of a function or command.

where <function Name >is the name of the function.


No comments:

Post a Comment