[go: up one dir, main page]

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

Summary of MATLAB Onramp

MATLAB Onramp provides an introduction to basic syntax, desktop management, array types, and operations in MATLAB. It covers creating matrices, indexing, multiple outputs, documentation, plotting, using tables, logical operations, and programming constructs. The document includes examples and descriptions for each topic to facilitate learning.

Uploaded by

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

Summary of MATLAB Onramp

MATLAB Onramp provides an introduction to basic syntax, desktop management, array types, and operations in MATLAB. It covers creating matrices, indexing, multiple outputs, documentation, plotting, using tables, logical operations, and programming constructs. The document includes examples and descriptions for each topic to facilitate learning.

Uploaded by

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

Summary of MATLAB Onramp

Basic syntax
Example Description
x = pi Create variables with the equal sign (=).
The left-side (x) is the variable name containing the value on the right-side
(pi).
y = sin(- You can provide inputs to a function using parentheses.
5)

Desktop management
Functio
n Example Description
save save data.m Save your current workspace to a MAT-file.
at
load load data.m Load the variables in a MAT-file to the Workspace.
at
clear clear Clear all variables from the Workspace.
clc clc Clear all text from the Command Window.
format format long Change how numeric output is displayed.

Array types
Example Description
4 scalar
[3 5] row vector
[1;3] column vector
[3 4 5;6 7 matrix
8]

Evenly-spaced vectors
Example Description
1:4 Create a vector from 1 to 4, spaced by 1, using the colon (:) operator.

1:0.5:4 Create a vector from 1 to 4, spaced by 0.5.


linspace(1,10, Create a vector with 5 elements. The values are evenly spaced
5) from 1 to 10.

Creating matrices
Example Description
rand(2) Create a square matrix with 2 rows and 2 columns.
Example Description
zeros(2,3 Create a rectangular matrix with 2 rows
) and 3 columns.

Indexing
Example Description

A(end,2 Access the element in the second column of the last row.
)
A(2,:) Access the entire second row
A(1:3,:) Access all columns of the first three rows.
A(2) = 1 Change the value of the second element an array to 11.
1

Array operations
Example Description
[1 1; 1 1]*[2 2;2 Perform matrix multiplication.
2]
ans =
4 4
4 4
[1 1; 1 1].*[2 2;2 Perform element-wise multiplication.
2]
ans =
2 2
2 2

Multiple outputs
Example Description
[xrow,xcol] = size( Save the number of rows and columns in x to two different variables.
x)
[xMax,idx] = max(x) Calculate the maximum value of x and its corresponding index
value.

Documentation
Example Description

doc rand Open the documentation page for


i the randi function.

Plotting
Example Description
plot(x,y,"ro-","LineWidth" Plot a red (r) dashed (--) line with a
Example Description
,5) circle (o) marker, with a heavy line width.

hold on Add the next line to existing plot.

hold off Create a new axes for the next plotted line.
title("My Title") Add a label to a plot.

Using tables
Example Description
data.HeightYards Extract the
variable HeightYards from
the table data.
data.HeightMeters = data.HeightYards*0. Derive a table variable from existing data.
9144

Logicals
Example Description
[5 10 15] > Compare a vector to the value 12.
12
v1(v1 > 6) Extract all elements in v1 that are greater than 6.
x(x==999) = Replace all values in x that are equal to 999 with the
1 value 1.

Programming
Example Description
if x > 0.5 If x is greater than 0.5, set the value
y = 3 of y to 3.
else
y = 4 Otherwise, set the value of y to 4.
end
for c = The loop counter (c) progresses through the
1:3 values 1:3 (1, 2, and 3).

disp(c) The loop body displays each value of c.


end

You might also like