matlab variables and data types - just focus on simple points

note

Difference between one % and two % commentsinsert image description here

Matlab variable

1. Variable names are case sensitive.
2. The variable name starts with a letter and can be composed of letters, numbers and underscores, but punctuation cannot be used.

Matlab data type

1. Numbers: 2 + 2, 5 - 2, 2 * 2, 5 / 2;

2. Characters and strings
Character (a single character enclosed in single quotes): 'a'
String (a string of characters enclosed in single quotes): 'abcdefg'

3. Matrix (one line is an array)
format: variable name = [ ]
spaces or commas are used to separate elements, and semicolons are used to break lines.
insert image description here

4. Cell array
Cell array is a unique data type in MATLAB. It is a kind of array. Its internal elements can belong to different data types. In terms of conceptual understanding, it can be considered as the structure in the c language, Objects in C++ are very similar. Cell array is a characteristic data type in matlab, which is different from other data types (such as character type, character array or string, and general arithmetic data and arrays). Its unique data access method determines its characteristics. It gives people a feeling of querying information, and can gradually track until all variables are translated into basic data information. Its class function output is cell.
a = cell(number of rows, number of columns)
insert image description here

5. Structure
books = struct('name', { {'Machine Learning','Data Mining'}},'price', [30 40])
'name', { {'Machine Learning'=key, value;
books.name
books.name(1): parentheses take cell
books.name{1}: square brackets take string
insert image description here

Guess you like

Origin blog.csdn.net/msmsa/article/details/129841715