sw_array and time_int

1 view (last 30 days)
Cagdas Tunceroglu
Cagdas Tunceroglu on 21 May 2023
Commented: Cagdas Tunceroglu on 21 May 2023
Hello, can you explain to me exactly what operations the sw_array and time perform in this code? Also, why does sw_array have 13 columns? And can you give me some examples of the mathematical operations represented by sw_array(:,:,2) = [0 1 0 1 1 1 1 1 1 1 0 1 0]? I've been struggling with understanding the code for the past three weeks, but I couldn't grasp it. Thanks in advance.
Best regards.
function [t1,t2,t0,int1,int2,int3,int4,int5,...
int6,int7,int8,int9,int10,int11,int12] ...
= fcn(M,angle,Sector,D,Ts)
a = M;
n = Sector;
t1 = a*Ts*sin(n*pi/3 - angle);
t2 = a*Ts*sin(angle - ((n-1)*pi/3));
t0 = Ts - t1 - t2;
tsh = D*Ts;
switch Sector
case 1
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t1/2;
int4 = int3 + tsh/6;
int5 = int4 + t2/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t2/2;
int10 = int9 + tsh/6;
int11 = int10 + t1/2;
int12 = int11 + tsh/6;
case 2
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t2/2;
int4 = int3 + tsh/6;
int5 = int4 + t1/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t1/2;
int10 = int9 + tsh/6;
int11 = int10 + t2/2;
int12 = int11 + tsh/6;
case 3
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t1/2;
int4 = int3 + tsh/6;
int5 = int4 + t2/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t2/2;
int10 = int9 + tsh/6;
int11 = int10 + t1/2;
int12 = int11 + tsh/6;
case 4
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t2/2;
int4 = int3 + tsh/6;
int5 = int4 + t1/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t1/2;
int10 = int9 + tsh/6;
int11 = int10 + t2/2;
int12 = int11 + tsh/6;
case 5
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t1/2;
int4 = int3 + tsh/6;
int5 = int4 + t2/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t2/2;
int10 = int9 + tsh/6;
int11 = int10 + t1/2;
int12 = int11 + tsh/6;
otherwise
int1 = t0/4 - tsh/4;
int2 = int1 + tsh/6;
int3 = int2 + t2/2;
int4 = int3 + tsh/6;
int5 = int4 + t1/2;
int6 = int5 + tsh/6;
int7 = int6 + t0/2 - tsh/2;
int8 = int7 + tsh/6;
int9 = int8 + t1/2;
int10 = int9 + tsh/6;
int11 = int10 + t2/2;
int12 = int11 + tsh/6;
end
function [Time_int,S1,S2,S3,S4,S5,S6] = ...
fcn(int1,int2,int3,int4,int5,int6,int7,int8,int9,int10,int11,...
int12,ref,Sector)
Time_int = 1+(ref>=int1) + (ref>=int2) + (ref>=int3) + (ref>=int4) ...
+ (ref >= int5) + (ref >= int6) + (ref >= int7) + (ref >= int8) ...
+ (ref >= int9) + (ref >= int10) + (ref >= int11) + (ref >= int12);
%% format of the array sw_array(x,y,z)
sw_array = zeros(6,13,6); %initialize the switching table
% x=[LegA LegB LegC] % y=[Timeint1 timeint2 ..] % z=[sector1 sector2 ..]
sw_array(:,:,1) = [0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1; ...
0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 1; ...
0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1];
sw_array(:,:,2) = [0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1; ...
0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1];
sw_array(:,:,3) = [0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1; ...
0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1; ...
0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 1];
sw_array(:,:,4) = [0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1; ...
0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 1; ...
0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1];
sw_array(:,:,5) = [0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 1; ...
0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1; ...
0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1];
sw_array(:,:,6) = [0 1 1 1 1 1 1 1 1 1 1 1 0; ...
1 1 0 1 0 1 0 1 0 1 0 1 1; ...
0 1 0 1 0 1 1 1 0 1 0 1 0; ...
1 1 1 1 1 1 0 1 1 1 1 1 1; ...
0 1 0 1 1 1 1 1 1 1 0 1 0; ...
1 1 1 1 0 1 0 1 0 1 1 1 1];
S1 = sw_array(1,Time_int,Sector);
S2 = sw_array(2,Time_int,Sector);
S3 = sw_array(3,Time_int,Sector);
S4 = sw_array(4,Time_int,Sector);
S5 = sw_array(5,Time_int,Sector);
S6 = sw_array(6,Time_int,Sector);
  2 Comments
Image Analyst
Image Analyst on 21 May 2023
I have no idea what sw_array is or why it is defined with 13 columns. Eveidently it will take on 13 y values for the second dimension.
I suggest you ask whoever wrote the code. But that's so obvious that I'm assuming you spent the last 3 weeks trying to contact them and they refuse to answer. So then I have to wonder, if you don't know what the code does, then why do you want to use it?
Cagdas Tunceroglu
Cagdas Tunceroglu on 21 May 2023
I am in the final stage of my doctoral study, and completing this will mark its culmination. I am very close to finding the solution, yet equally far away at the same time. :D Unfortunately, the authors of the code haven't provided any feedback, and I don't have any other simulation to proceed with apart from this code.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!