You are on page 1of 1

Session 2: Matrixs,Strings, Data Structure

Matrixes============================= C3 = 'A':'Z'
A = zeros(3) C4 = 'a':'Z'
B = zeros(2,3)

C = ones(2) % ASCII Code


Cp = pi*ones(3,2) d1 = double ('A')
d1 = double ('Z')
% pascal --------- d1 = double ('az')
D = pascal(3) s1 = char(d1)
G = hilb (4)
Gs = sym(G) da = double('Matlab coding')

% 2D, 3D --------- xx = 'A':'z'


A3d = zeros(4,3,2);
A4d = ones(4,3,2,2); %% Cells and Struct===================
clc, clear
% logical indexing ---------- % cells
A = 1:10; C{1} = 2*ones(4);
Ind1 = A < 5 C{2} = hilb(3);
A(Ind1) C{3} = 'Hellow world'
Ind2 = A > 2 & A < 7
A(Ind2) C{2}(2,3)
C{3}(1,5)
% find
AM = [3 4 5; 5 6 1; 6 9 2 ] % sturct
S.varA = 2*ones(4);
Ind = AM == 9 S.varB = hilb(3);
IndF = find(Ind) S.varC= 'Hellow world'
[r, c] = ind2sub(size(AM), IndF)
% ---------------- S.varC(1,8)
% sort
% combination of cells and struct
A = [3 6 1 2 8] CS{1}.Name = 'Hamed'
sort(A) CS{2}.Name = 'Mehdi'
sort(A, 'descend') CS{2}.Age = 32

% rand % Struct Array


A = rand(1,5)% uniform distribution in SA(1).name = 'A'
(0, 1) SA(1).grade = 19
Ai = floor(rand(1,5)*6 + 1)
AI2 = randi(6, [1,5]) SA(2).name = 'B'
SA(2).grade = 15
% Matrix Inverse
AM = [3 4 5; 5 6 1; 6 9 2 ]
M1inv = inv(AM) SA(3).name = 'C';
M1inv2 = AM^-1 SA(3).grade = 16;

% Solveing system of linear equations SA.grade


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

x1 = A^-1 * B
x2 = A \ B

%% character ==========================

C1 = 'Matlab'
C1(2)
C2 = ['Matlab', 'Course']
C2 = ['Matlab'; 'Course']

MATLAB Course By: Mansour Torabi

You might also like