-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMATLAB_project.m
45 lines (45 loc) · 1017 Bytes
/
MATLAB_project.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
%% Print Array In Spiral Order
A = input("Enter the matrix : \n")
%i am changing something idk What
%% Define Processing Inputs
% Define Row And Coloums.
% Define Left Most , Right Most, Top Most and Bottom most Rows and
% Coloumn's index initially.
[row,col] = size(A);
L = 1;T = 1;R = col;B = row;dir =0;
%% Matrix Processsing
fprintf("Given Output Spiral Matrix\n")
while(T <= B && L <= R)
% Traversing 1st from L -> R
if (dir == 0)
for i= L:R
fprintf("%d ",A(T,i));
end
T = T+1;
dir = 1;
end
if(dir ==1)
for i= T:B
fprintf("%d ",A(i,R));
end
R = R-1;
dir = 2;
end
% Traversing 1st from R -> L
if (dir == 2)
for i=R:-1:L
fprintf("%d ",A(B,i));
end
B = B-1;
dir =3;
end
% Traversing 1st from B -> T
if (dir ==3)
for i= B:-1:T
fprintf("%d ",A(i,L));
end
L = L+1;
dir = 0;
end
end
By - Devendra Kumar Tarak