double | Convert to double precision |
single | Convert to single precision |
int8 | Convert to 8-bit signed integer |
int16 | Convert to 16-bit signed integer |
int32 | Convert to 32-bit signed integer |
int64 | Convert to 64-bit signed integer |
uint8 | Convert to 8-bit unsigned integer |
uint16 | Convert to 16-bit unsigned integer |
uint32 | Convert to 32-bit unsigned integer |
uint64 | Convert to 64-bit unsigned integer |
y = int64(-6548313425); % Create a 64-bit signed integer
x = double(y) % Convert to double precision floating number
x = single(y) % Convert to single-precision floating number
mydata = uint16(magic(3)) % Convert a double array to uint16
% magic(3) is a double array by default
double('a') % Convert a character to a double-precision format
% the decimal equivalent in the ASCII coding system
Chracter arrays provide storage for text data in MATLAB
char
: Converts to character arraychar(98)
% the character represented by that decimal number in ASCII
Creating character array:
title = ['Harold A. Jorgensen ' ; 'Assistant Project Manager' ; 'SFTware Corp. ']
% Each row must contain the same number of characters
['a', 98]
name = 'myname' ;
domain = 'mydomain' ;
ext = 'com' ;
address = strcat(name , '@' , domain , '.' , ext )
Q = char('Holly','Steven','Meagan','David','Michael','Heidi')
R = [98;84;73;88;95;100];
table = [Q,R]
A = 1:3;
B = ['abcdefg'] ;
C = single([1 2 3; 4 5 6]);
my_cellarray = {A, B, C}
my_cellarray{1}
my_cellarray{2}
my_cellarray{3}
my_cellarray{1}(1,2)
my_cellarray{3}(2,3)
myCell = {1, 2, 3; 'abc', rand(5,10,2) , {11; 22 ; 33}}
myCell(1:2,2:3)
cell(n)
: Returns an n-by-n cell array of empty matricescell(3)
cell(m,n)
: Returns an m-by-n cell array of empty matricescell(2,4)
cell(s1,s2, ..., sN)
: Returns a s1-by-s2-by-...-by-sN cell array of empty matrices where s1, s2, ..., sN indicate the size of each dimensionA = cell(3,4,2,2)
size(A)
cell ( size (A))
: Create a cell array of empty matrices that is the same size as matrix AA = [1 3 4 ; 2 8 6];
cell(size(A))
A = 1:3;
B = ['abcdefg'];
C = single([1 2 3; 4 5 6]);
my_structure.numbers = A;
my_structure.numbers
my_structure.letters = B;
my_structure.letters
my_structure.othernumbers = C;
my_structure.othernumbers
my_structure
struct( field ,value)
: Creates a structure array with the specified field and values. The value input argument can be any data type, such as a numeric, logical, character, or cell arrayf = 'myfield';
v = {'abc'; [1;2;3]; magic(5)};
struct(f,v)
struct(field1 ,value1, ..., fieldN ,valueN)
: creates a structure array with multiple fields. Any nonscalar cell arrays in the set value1, ..., valueN must have the same dimensionsfield1 = 'f1'; value1 = zeros(1,10);
field2 = 'f2' ; value2 = {'a' , 'b'};
field3 = 'f3' ; value3 = {pi , pi.^2};
field4 = 'f4' ; value4 = {'fourth'};
s = struct(field1, value1, field2, value2, field3, value3, field4, value4)
s(2)
s = struct('f1', 'a', 'f2', [ ]) % Creates a structure with an empty field
s = struct('f1', {}, 'f2', {} , 'f3', {}) % Creates an empty structure with several fields
s(1).f2 = ('b') % Assings a value to a field in an empty structure
x = [ 1 2 3 ; 4 5 6];
y = 10*x;
z = 10*y;
w = 10*z;
my_3D_array(:,:,1) = x;
my_3D_array(:,:,2) = y;
my_3D_array(:,:,3) = z;
my_3D_array(:,:,4) = w;
my_3D_array
iscategorical | Determine whether input is categorical array |
iscell | Determine whether input is cell array |
ischar | Determine whether input is character array |
isfloat | Determine whether input is floating-point array |
isinteger | Determine whether input is integer array |
islogical | Determine whether input is logical array |
isnumeric | Determine whether input is numeric array |
isstruct | Determine whether input is structure array |
class | Determine the class of the object |
myCell = {1, 2, 3; 'abc', rand(5,10,2) , {11; 22 ; 33}}
class(myCell)
iscell(myCell)
ischar(myCell)
cellstr | Convert to cell array of character vectors |
int2str | Convert integer to string |
mat2str | Convert matrix to string |
num2str | Convert number to string |
str2double | Convert string to double-precision value |
str2num | Convert string to number |
cell2struct | Convert cell array to structure array |
mat2cell | Convert array to cell array with potentially different sized cells |
num2cell | Convert array to cell array with consistently sized cells |
struct2cell | Convert structure to cell array |
a = magic(3)
num2cell(a)