Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions matlab_for_beginners/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


The best way to learn matlab programming is to go through the basics problems along with the code.
It allows us to understand the matlab language in a better way.

This, matlab_for_beginners tutorial is divided into different parts. Just go one by one through each part.
After completion of all parts you will have good basic knowledge of matlab.

All The Best.

45 changes: 45 additions & 0 deletions matlab_for_beginners/matlab_introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
author - Puneet Prakash Arya
email - puneetarya66@gmail.com
github - https://github.com/puneet-pr-arya




"MATLAB" is a programming platform designed specifically for engineers and scientists.
The heart of MATLAB is the MATLAB language, a matrix-based language allowing the most natural expression of computational mathematics.


What can you do with MATLAB?

Using MATLAB, you can:

Analyze data
Develop algorithms
Create models and applications


Matlab Advantages

(.) Implement and test your algorithms easily
(.) Develop the computational codes easily
(.) Debug easily
(.) Use a large database of built in algorithms
(.) Process still images and create simulation videos easily
(.) Symbolic computation can be easily done
(.) Call external libraries
(.) Perform extensive data analysis and visualization
(.) Develop application with graphics user interface


Who uses MATLAB?

Millions of engineers and scientists in industry and academia use MATLAB.
You can use MATLAB for a range of applications, including deep learning and machine learning,
signal processing and communications, image and video processing, control systems, test and measurement,
computational finance, and computational biology.


With these tutorials, i would like to give all of you a basic idea of matlab so that all of you got familiar with the platform
and can work on it in future.

Thank you and all the best.
21 changes: 21 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


This part-1 contains basics programs of matlab to make you familiar with the language.
For better understanding the basics of the matlab programming,
please go through the programs according the following
sequence. Details of each the programs is given alongside:--

1- add.m ( addition of numbers)
2- equal.m ( The meaning of "a = b" )
3- math.m ( Basic math operations )
4- equal_add.m ( The meaning of "a = b", continued )
5- print.m ( Formatted output )
6- formatted_output.m ( Formatted output continued )
7- array.m ( Simple addition of array )
8- individual_eL_add.m ( Extracting an individual element of an array )
9- comment.m ( The use of comment)
10- continuation.m ( Continuation to next line )
11- intr_math_fun.m ( Intrinsic math functions and constants )
12- nam_var.m ( Naming a variable )
13- Plot a graph ( for making a quick plot)

5 changes: 5 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/add.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%%Addition
a = 3;
b = 5;
c = a+b
%%Output:8
9 changes: 9 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/array.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%%Ex. 7 Arrays


a = [3 6 7];
b = [1 9 4];
c = a + b


%Output: 4 15 11
15 changes: 15 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/comment.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%%Ex. 9 Comment
%
% This program demonstrates how to "comment out"
% a segment of code

A = 3;
B = A*A;
%
% B = 2*B <--- This statement is not executed
%
C = A+B



%Output: c = 12
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%%Ex. 10 Continuation to next line
summation1 = 1 + 3 + 5 + 7 ...
+ 9 + 11


%Note: The three periods (...) allow continuation to the next line of commands. The two
% lines in the above example are essentially one line of "summation1 = 1+3+5+7+9+11".
11 changes: 11 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/equal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%%Ex. 2 The meaning of "a = b"


%In Matlab and in any programming language, the statement "a = b" does not mean
%"a equals b". Instead, it prompts the action of replacing the content of a by the
%content of b.
a = 3;
b = a;
b

%Output:3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%%Ex. 4 The meaning of "a = b", continued
a = 3;
a = a+1;
a

%Output:4

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%%Ex. 6 Formatted output
a = 3;
b = a*a;
c = a*a*a;
d = sqrt(a);
fprintf('%4u square equals %4u \r', a, b)
fprintf('%4u cube equals %4u \r', a, c)
fprintf('The square root of %2u is %6.4f \r', a, d)


%Output: 3 square equals 9
% 3 cube equals 27
% The square root of 3 is 1.7321
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%%Ex. 8 Extracting an individual element of an array


a = [3 6 7];
b = [1 9 4 5];
c = a(2) + b(4)


%Output: c = 11
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%%Ex. 11 Intrinsic math functions and constants
x = pi;
y = sin(pi/2)
z = exp(-sin(pi/2))


%Output:
% y = 1
% z = 0.3679
17 changes: 17 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/make_graph.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%% Ex. 13 Making a quick plot
x = [0:0.1:20];
y = sin(x);
plot(x,y)




% remaks : Remarks: This only serves as a very quick example of what Matlab can do in making
% plots.The first line is equivalent to x = [0 0.1 0.2 0.3 ... 19.8 19.9 20]. It
% assigns the content of x which is an array of 201 elements. The "0:0.1:20" means the
% 201 numbers are evenly spaced. They start from 0 and end at 20 with an increment of
% 0.1. The second line gives the content of the new array, y, as
% y = [sin(x(1)) sin(x(2)) sin(x(3)) ... sin(x(200)) sin(x(201))] ,
% or
% y = [sin(0) sin(0.1) sin(0.2) ... sin(19.9) sin(20)] .
% The 3rd line makes a plot of y vs. x.
7 changes: 7 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/math.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%%Ex. 3 Basic math operations

a = 3;
b = 9;
c = 2*a+b^2-a*b+b/a-10

%Output:53
9 changes: 9 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/nam_var.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%%Ex. 12 "Clear" a variable

%Naming a variable

%(i) Matlab variables are case sensitive. For example, "ASU" and "asu" are two different
%variables. (ii) An underscore (_) or a number (0-9) can also be part of the name of a
%variable. For example, "MAE_384" is a legitimate variable name. (iii) Some names are
%reserved for special constants. For example (see Ex. 11), "pi" is an intrinsic constant
%with a fixed value of 3.14159...
4 changes: 4 additions & 0 deletions matlab_for_beginners/part_1(learn_basic_programing)/print.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%%Ex. 5 Formatted output

fprintf('Hello')
%Output:Hello
26 changes: 26 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


This part-2 introduces the concept of loops in the matlab language.

For understanding the concept of looping just go through the programs one by one.
After that u will be able to apply the loops.

1 - program1 - ( Loop: Using for command )

2- program2 - ( For loop: Utility of the dummy index )


3 - program3 - ( For loop: More on the dummy index)

4 - program4 - (Treatment of array within a loop)

5 - program5 - ( Double loop )


6 - program6 - ( another double lopp )


7- program7 - ( More complicated use of loop and index )


8- wh_loop - ( while loop )
18 changes: 18 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%% The for loop
%Ex. 1 Loop: Using for command
b = 3;
for k = 1:5
b
end


%Output:
% 3
% 3
% 3
% 3
% 3

%Remark: The blue-colored segment in lines 2-4 forms a "for-loop". The statement
% sandwiched between "for k = 1:5" and "end" is repeated 5 times, with the "k" index
% going from 1 to 5 step 1
15 changes: 15 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%% Ex. 2 For loop: Utility of the dummy index

b = 3;
for k = 1:5
b^k
end
%Output:
% 3
% 9
% 27
% 81
% 243

%Remark: The outputs are 3^1, 3^2, 3^3, 3^4, and 3^5. the value of "k" keeps changing as
% we go through the loop
10 changes: 10 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%% Ex.3 For loop: More on the dummy index

sum1 = 0;
for k = 1:9
sum1 = sum1+k;
end
sum1
%Output:
% 45
% Remark: this program performs the summation of 1+2+3+4+5+6+7+8+9 (= 45).
16 changes: 16 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program4.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%% Ex.4 Treatment of array within a loop


b = [3 8 9 4 7 5];
sum1 = 0;
for k = 1:4
sum1 = sum1+b(k);
end
sum1


%Output:
% 24

% Remark: This program performs the summation of sum1 = b(1)+b(2)+b(3)+b(4) =
% 3+8+9+4 = 24
15 changes: 15 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program5.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%% Ex. 5 Double loop

sum1 = 0;
for n = 1:2
for m = 1:3
sum1 = sum1+n*m;
end
end
sum1


%Output:
18
% Remark: this program performs the summation of
% Sum1 = 1*1+1*2+1*3 +2*1+2*2+2*3 = 18
16 changes: 16 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program6.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%% Ex. 6 Double loop

for n = 1:2
for m = 1:3
fprintf('n = %3u m = %3u \r', n, m)
end
end


%Output:
% n = 1 m = 1
% n = 1 m = 2
% n = 1 m = 3
% n = 2 m = 1
% n = 2 m = 2
% n = 2 m = 3
17 changes: 17 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/program7.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%% Ex. 7 More complicated use of loop and index


b = [2 5 7 4 9 8 3];
c = [2 3 5 7];
sum1 = 0;
for k = 1:4
sum1 = sum1+b(c(k));
end
sum1
%Output:
% 24
% Remark: This program performs the summation of
% sum1 = b(c(1))+b(c(2))+b(c(3))+b(c(4))
% = b(2)+b(3)+b(5)+b(7)
% = 5+7+9+3
% = 24
16 changes: 16 additions & 0 deletions matlab_for_beginners/part_2(basic_looping)/wh_loop.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%% The while loop


x = 3;
while (x < 100)
x = x*3;
end
x


% Output:
% x = 243
% Remark: One can think of a while loop as a combination of a for loop and an if
% statement. Here, the looping will keep going indefinitely as long as the condition,
% (x < 100), is satisfied. Therefore, the value of x progresses from 3, 9, 27, 81, to 243
% when the loop is terminated.
Loading