0% found this document useful (0 votes)
2 views

Week 1 Part 3 Fundamentals

The document provides an introduction to MATLAB, covering how to access it, the MATLAB desktop, and basic debugging techniques. It discusses various data types in MATLAB, including floating-point, integer, strings, and logical values, as well as more complex structures like tables and cell arrays. Additional exercises encourage users to practice creating strings, character arrays, and logical variables.

Uploaded by

Ngọc Vi Cao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Week 1 Part 3 Fundamentals

The document provides an introduction to MATLAB, covering how to access it, the MATLAB desktop, and basic debugging techniques. It discusses various data types in MATLAB, including floating-point, integer, strings, and logical values, as well as more complex structures like tables and cell arrays. Additional exercises encourage users to practice creating strings, character arrays, and logical variables.

Uploaded by

Ngọc Vi Cao
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Fundamentals

Where do I find MATLAB? Here!

Do I have to have MATLAB installed on my computer right


now? No, you can use MATLAB Online!

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 1


Table of Contents

What we've covered this week in Part 2Data Types


Extra LearningWhat we've covered this week in Part 3

MATLAB Live Script

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 2


What we've covered this week in Part 2
This week in Part 2 we learnt about:
 How to access MATLAB
 The MATLAB desktop
 MATLAB Cheat Sheet
 Obtaining help in MATLAB
 Basic debugging in MATLAB

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 3


Data Types
There are many different data types, or classes, that you can work with in MATLAB. You
can build matrices and arrays of the following data types:
• floating-point
• integer data
• characters and strings,
• logical true and false values, and so on

The following data types provide a way to store dissimilar types of data in the same
container:
• tables
• timetables
• structures
• cell arrays

There are 16 fundamental classes in MATLAB, each of these classes is in the form of a
matrix or array (more on matrices and arrays in week 2: “Arrays, Matrices and
Operators). This matrix or array is a minimum of 0-by-0 in size and can grow to an n-
dimensional array of any size.
© 2023 Introduction to Programming in MATLAB (1), Fundamentals 4
Data Types
All the fundamental MATLAB classes are shown in the diagram below:

See this table that describes the fundamental classes in more detail.
Let’s see some examples using some of these fundamental data types.

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 5


Data Types
Let’s create a string and character array.
Run the code (using the Run Section button ), and check the class of str and chr in
the Workspace:

str = "This is a string array" %Enclose text in double quotes to create a


string
chr = 'This is a character array' %Enclose text in single quotes to create a
character array

MATLAB displays strings with double quotes and character vectors with single quotes.
The difference between these two data types, is that str will be stored as a 1-by-1 string
or a string scalar whereas chr will be stored as a 1-by-12 character vector (confirm this in
the Workspace browser).

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 6


Data Types
Now you try! Create a string of your name and a character array of your surname:

%Write your code here


%String of your name
%Character array of your surname

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 7


Extra Learning
We can store our two variables (more on variables in Variables and Commands
section in Part 4 of Week 1), str and chr, and an additional numeric variable in one
container data type :

number = 25;

%Cell array data type


cellArray = {str, chr, number} %Cell array made up of a string, character
array and a double

%Structure data type


structure.stringField = str; %Structure with a field assigned a value of class
string
structure.characterArrayField = chr; %Structure with a field assigned a value
of class char
structure.numericDoubleField = number; %Structure with a field assigned a
value of class double

structure %Structure with three fields assigned values of different classes.

%Table data type


© 2023
table(str, Introduction'VariableNames',
{chr}, number, to Programming in MATLAB {'String',
(1), Fundamentals 8
'Character', 'Double'})
Extra Learning
Now you try! Create a table with your name, surname, and your age:

%Write your code here


%Double value of your age
%Table with three variables/columns: Name, Surname and Age

We can create a logical data type variable in a few ways, one of them is to use
MATLAB built-in functions, in our case we’ll use the isa function to check a variable’s data
type:
tf = isa(str, 'char') %We’re checking if str is a character, this should return a
false

Now you try! Create a logical variable:


%Write your code here
%Check the data types of one of your variables

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 9


What we've covered this week in Part 3
This week in Part 2 we learnt about:

 Data types

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 10


MATLAB Live Script
Click on the link below for this lecture’s MATLAB live Script

• Week_1_Part_3_Fundamentals.mlx

© 2023 Introduction to Programming in MATLAB (1), Fundamentals 11

You might also like