I was trying to simulate this piece of code as part of simulation when this error occured.I am not able to understand how num_cycles is calculated in the above code.The code is part of a set of equations governing the time delay required for gate signal for a mosfet
function [Tsa,Tsb]=gentimeseries(m1,tp,num_cycles)
num_angles=(360/5)+1;
ts=(tp/(num_angles*50));
ts
tsa=[];
tsb=[];
alpha1=0;
ta1=0;
tb1=0;
tsa=[tsa;[ta1,0]];
tsb=[tsb;[tb1,0]];
while alpha1<=360
[wa,da,wb,db]=svp(m1,alpha1);
da=da*ts/100;
db=db*ts/100;
wa=wa*ts/100;
wb=wb*ts/100;
i=1;
while i<=50
ta1=ta1+da;
tsa=[tsa;[ta1,1]];
ta1=ta1+wa;
tsa=[tsa;[ta1,0]];
ta1=ta1+da;
tsa=[tsa;[ta1,0]];
i=i+1;
end
i=1;
while i<=50
tb1=tb1+db;
tsb=[tsb;[tb1,1]];
tb1=tb1+wb;
tsb=[tsb;[tb1,0]];
tb1=tb1+db;
tsb=[tsb;[tb1,0]];
i=i+1;
end
alpha1=alpha1+5;
end
x=tsa(:,2);
y=tsa(:,1);
plot(y,x,'.')
Tsa=timeseries(tsa(:,2),tsa(:,1));
Tsb=timeseries(tsb(:,2),tsb(:,1));
n_cycle=1;
while n_cycle<=num_cycles
tta=Tsa;
tta.time=tta.time+ta1;
Tsa=Tsa.append(tta);
ttb=Tsb;
ttb.time=ttb.time+tb1;
Tsb=Tsb.append(ttb);
ta1=ta1+ta1;
tb1=tb1+tb1;
n_cycle=n_cycle+1;
end
end
Related
I want to code a FEM programme and here is my code
N1=2; %横向分解成2个元素
N2=2; %纵向分解成2个元素
N=2*N1*N2;
%三角元
top=1;
bottom=0;
left=0;
right=1;
h1=(right-left)/N1;
h2=(top-bottom)/N2;
T=zeros(3,2*N1*N2);%生成初始T矩阵
N10=N1+1;
N20=N2+1;
%先把每个element的行列转化为每个element对应的起始node的坐标,然和把坐标转化为index
for i=1:N2
for j=1:2*N1
if mod(j,2)==1
T(:,2*N1*(i-1)+j)=[(i-1)*N10+ceil(j/2);i*N10+ceil(j/2);(i-1)*N10+ceil(j/2)+1];
else
T(:,2*N1*(i-1)+j)=[(i-1)*N10+j/2+1;i*N10+j/2;i*N10+j/2+1];
end
end
end
P=zeros(2,(N1+1)*(N2+1));
for i=1:N1+1
for j=1:N2+1
P(:,(i-1)*(N1+1)+j)=[left+(i-1)*h1;bottom+(j-1)*h2];
end
end
N1_1= 2*N1;
N2_1= 2*N1;
N_1= 2*N1_1*N2_1;
%三角元
h1_1=(right-left)/N1_1;
h2_1=(top-bottom)/N2_1;
N10_1=N1_1+1;
N20_1=N2_1+1;
P_b=zeros(2,(N1_1+1)*(N2_1+1));
for i=1:N1_1+1
for j=1:N2_1+1
P_b(:,(i-1)*(N1_1+1)+j)=[left+(i-1)*h1_1;bottom+(j-1)*h2_1];
end
end
boundarynodes=zeros(2,N2_1+1+N1_1+N2_1+N1_1-1);
for j=1:2*N2_1+2*N1_1
boundarynodes(1,j)=-1;
end
for i=1:N1_1+1
boundarynodes(2,i)=(i-1)*(N1_1+1)+1;
end
for i=N1_1+2:N1_1+1+N2_1
boundarynodes(2,i)=(N1_1+1-1)*(N1_1+1)+i-(N1_1);
end
for i=N1_1+1+N2_1+N1_1:-1:N1_1+N2_1+2
boundarynodes(2,i)=((-i+2*N1_1+N2_1+2)-1)*(N1_1+1)+N1_1+1;
end
for i=N1_1+N2_1+N2_1+N1_1:-1:N1_1+2+N2_1+N1_1
boundarynodes(2,i)=-i+2*N1_1+2*N2_1+2;
end
%建立坐标到index函数
T_b=zeros(6,2*N1*N2);
c2i=#(i,j) (i-1)*(N1_1+1)+j;
for i=1:N1
for j=1:2*N2
if mod(j,2)==1
i_0=2*i-1;
j_0=2*ceil(j/2)-1;
T_b(:,2*N1*(i-1)+j)=[c2i(i_0,j_0);c2i(i_0+2,j_0);c2i(i_0,j_0+2);c2i(i_0+1,j_0);c2i(i_0+1,j_0+1);c2i(i_0,j_0+1)];
else
i_0=2*i-1;
j_0=2*(j/2+1)-1;
T_b(:,2*N1*(i-1)+j)=[c2i(i_0,j_0);c2i(i_0+2,j_0-2);c2i(i_0+2,j_0);c2i(i_0+1,j_0-1);c2i(i_0+2,j_0-1);c2i(i_0+1,j_0)];
end
end
end
A=sparse((N1_1+1)*(N2_1+1),(N1_1+1)*(N2_1+1));
for n=1:N
y_n2=P_b(2,T_b(2,n));
y_n3=P_b(2,T_b(3,n));
y_n1=P_b(2,T_b(1,n));
y_n4=P_b(2,T_b(4,n));
y_n5=P_b(2,T_b(5,n));
y_n6=P_b(2,T_b(6,n));
x_n3=P_b(1,T_b(3,n));
x_n2=P_b(1,T_b(2,n));
x_n1=P_b(1,T_b(1,n));
x_n4=P_b(1,T_b(4,n));
x_n5=P_b(1,T_b(5,n));
x_n6=P_b(1,T_b(6,n));
Y_n2=P(2,T(2,n));
Y_n3=P(2,T(3,n));
Y_n1=P(2,T(1,n));
X_n3=P(1,T(3,n));
X_n2=P(1,T(2,n));
X_n1=P(1,T(1,n));
xmin=X_n1;
xmax=xmin+h1;
J_n=(X_n2-X_n1)*(Y_n3-Y_n1)-(X_n3-X_n1)*(Y_n2-Y_n1);
x_hat=#(x,y) ((Y_n3-Y_n1)*(x-X_n1)-(X_n3-X_n1)*(y-Y_n1))/J_n;
y_hat=#(x,y) ((X_n2-X_n1)*(y-Y_n1)-(Y_n2-Y_n1)*(x-X_n1))/J_n;
if mod(n,2)==1
ymin= Y_n1;
ymax=#(x) Y_n3+((Y_n3-Y_n2)/(X_n3-X_n2))*(x-X_n3);
else
ymin=#(x) Y_n2+((Y_n2-Y_n1)/(X_n2-X_n1))*(x-x_n2);
ymax= Y_n1;
end
for i=1:6
for j=1:6
fun=#(x,y)...
(p_i_x(x_hat(x,y),y_hat(x,y),i))*((Y_n3-Y_n1)/J_n)+...
(p_i_y(x_hat(x,y),y_hat,i))*((Y_n1-Y_n2)/J_n)*...
(p_i_x(x_hat(x,y),y_hat(x,y),j)*((Y_n3-Y_n1)/J_n)+...
(p_i_y(x_hat(x,y),y_hat(x,y),j))*((Y_n1-Y_n2)/J_n))+...
((p_i_x(x_hat(x,y),y_hat(x,y),i))*((X_n1-X_n3)/J_n)+...
(p_i_y(x_hat(x,y),y_hat(x,y),i))*((X_n2-X_n1)/J_n))*...
((p_i_x(x_hat(x,y),y_hat(x,y),j))*((X_n1-X_n3)/J_n)+...
(p_i_y(x_hat(x,y),y_hat(x,y),j))*(X_n2-X_n1)/J_n);
r=integral2(fun,xmin,xmax,ymin,ymax);
A(T_b(j,n),T_b(i,n))=A(T_b(j,n),T_b(i,n))+r;
end
end
end
please ignore the chinese comment!
the above main programme also use the following two programmes
function r=p_i_x(x,y,i)
i_x=[4*x+4*y-3,4*x-1,0,-8*x-4*y+4,4*y,-4*y];
r=i_x(i);
end
function r=p_i_y(x,y,i)
i_y=[4*x+4*y-3,0,4*y-1,-4*x,4*x,-8*y-4*x+4];
r=i_y(:,i);
end
when I try to execute fun(0,1), "Undefined operator '*' for input arguments of type 'function_handle'." occurs I don't know how to fix this and other answers don't help, how to fix this?
Recently wrote code that establishes a connection between two instances of matlab. I can send messages through the TCP-IP connection which will execute code. Now I'm trying to setup the code to be interruptible as I would like to start/stop a function through TCP-IP. Problem though is that sending a second command does nothing until the function is completed. Is there a way to interrupt a TCP-IP callback function?
code:
classdef connectcompstogether<handle
properties
serverIP
clientIP
tcpipServer
tcpipClient
Port = 4000;
bsize = 8;
earlystop
end
methods
function gh = connectcompstogether(~)
% gh.serverIP = '127.0.0.1';
gh.serverIP = 'localhost';
gh.clientIP = '0.0.0.0';
end
function SetupServer(gh)
gh.tcpipServer = tcpip(gh.clientIP,gh.Port,'NetworkRole','Server');
set(gh.tcpipServer,'OutputBufferSize',gh.bsize);
fopen(gh.tcpipServer);
display('Established Connection')
end
function SetupClient(gh)
gh.tcpipClient = tcpip(gh.serverIP,gh.Port,'NetworkRole','Client');
set(gh.tcpipClient, 'InputBufferSize',gh.bsize);
set(gh.tcpipClient, 'BytesAvailableFcnCount',8);
set(gh.tcpipClient, 'BytesAvailableFcnMode','byte');
set(gh.tcpipClient, 'BytesAvailableFcn', #(h,e)gh.recmessage(h,e));
fopen(gh.tcpipClient);
display('Established Connection')
end
function CloseClient(gh)
fclose(gh.tcpipClient);
gh.tcpipClient = [];
end
end
methods
function sendmessage(gh,message)
fwrite(gh.tcpipServer,message,'double');
end
function recmessage(gh,h,e)
Message = fread(gh.tcpipClient,gh.bsize/8,'double');
if Message == 444
gh.Funwithnumbers();
elseif Message == 777
gh.earlystop = 1;
end
end
function Funwithnumbers(gh)
x=1;
while true
if x > 5000, break;end
if gh.earlystop == 1,break;end
x = x+1;
display(x)
end
end
end
end
for ease to understand code.
server
Ser = connectcompstogether;
ser.SetupServer();
ser.sendmessage(333);
Client
cli = connectcompstogether;
cli.SetupClient();
Update:
So after going through the web, I have found out based on this post that the tcpip callback cannot be interrupt. The post was in 2017 which means my 2016a version definitely cannot interrupt a callback.
So An update to my question, Is it possible to start a subprocess in matlab to run the function. I just want to use the callback to start code. If I can start a subprocess from the callback. Than I should be able to free up the main process and use tcpip to start/stop a function on a different computer.
Update 2:
So I tried to utilize parallel processing using the 'spmd' command but the problem still persisted.
function recmessage(gh,h,e)
Message = fread(gh.tcpipClient,gh.bsize/8,'double');
spmd
switch labindex
case 1
if Message == 444
gh.Funwithnumbers();
elseif Message == 777
gh.earlystop = 1;
end
end
end
end
You may use a timer object, which is convenient to delay the execution of some function.
t=timer('ExecutionMode','singleShot', 'StartDelay',0, 'TimerFcn',#myCallback);
start(t);
In this case, the StartDelay is 0, so myCallback will be almost immediately added to the queue of tasks to be processed by Matlab. The execution however will start only after the callback to the tcpip object has been completed. It will block the queue once started, however.
You may try something like:
properties
t=timer('ExecutionMode','singleShot', 'StartDelay',0, 'TimerFcn',#myCallback);
end
function tcpipCallback(gh,tcpObj,~)
message=fread(tcpObj,1,'double');
if message==444
if strcmp(get(t,'Running'),'on')
error('The function is running already');
else
set(gh.t,'UserData',false);
start(gh.t);
end
elseif message==777
set(gh.t,'UserData',true);
end
function myCallback(tObj,~)
ii=0;
while ii<5000
if get(tObj,'UserData'),break,end
ii=ii+1;
pause(.0001); %Pause to interrupt the callback; drawnnow might work too; or perhaps this is not needed at all.
end
end
I have a code that computes the max value. this code consists of four variables www is the function of a,b, and c labaled xx, yy, and zz respectively, so my question is how can i plot www against xx,yy, and zz? Thanks for helping
objfun file
function f=W4qubit(x,a,b,c,d)
c1=-cos(x(1))*(cos(x(5))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15))))+...
cos(x(7))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15)))))-...
cos(x(3))*(cos(x(5))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15))))-...
cos(x(7))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15)))));
c2=cos(x(1))*(cos(x(5))*(sin(x(9))*(sin(x(13))*cos(x(10)-x(14))-sin(x(15))*cos(x(10)-x(16)))-...
sin(x(11))*(sin(x(13))*cos(x(12)-x(14))+sin(x(15))*cos(x(12)-x(16))))+...
cos(x(7))*(sin(x(11))*(sin(x(15))*cos(x(12)-x(16))-sin(x(13))*cos(x(12)-x(14)))-...
sin(x(9))*(sin(x(13))*cos(x(10)-x(14))+sin(x(15))*cos(x(10)-x(16)))))+...
cos(x(3))*(cos(x(5))*(sin(x(11))*(sin(x(15))*cos(x(12)-x(16))-sin(x(13))*cos(x(12)-x(14)))-...
sin(x(9))*(sin(x(13))*cos(x(10)-x(14))+sin(x(15))*cos(x(10)-x(16))))-...
cos(x(7))*(sin(x(9))*(sin(x(13))*cos(x(10)-x(14))-sin(x(15))*cos(x(10)-x(16)))-...
sin(x(11))*(sin(x(13))*cos(x(12)-x(14))+sin(x(15))*cos(x(12)-x(16)))));
c3=cos(x(1))*(sin(x(5))*(cos(x(9))*(sin(x(13))*cos(x(6)-x(14))-sin(x(15))*cos(x(6)-x(16)))-...
cos(x(11))*(sin(x(13))*cos(x(6)-x(14))+sin(x(15))*cos(x(6)-x(16))))+...
sin(x(7))*(cos(x(11))*(sin(x(15))*cos(x(8)-x(16))-sin(x(13))*cos(x(8)-x(14)))-...
cos(x(9))*(sin(x(13))*cos(x(8)-x(14))+sin(x(15))*cos(x(8)-x(16)))))+...
cos(x(3))*(sin(x(5))*(cos(x(11))*(sin(x(15))*cos(x(6)-x(16))-sin(x(13))*cos(x(6)-x(14)))-...
cos(x(9))*(sin(x(13))*cos(x(6)-x(14))+sin(x(15))*cos(x(6)-x(16))))-...
sin(x(7))*(cos(x(9))*(sin(x(13))*cos(x(8)-x(14))-sin(x(15))*cos(x(8)-x(16)))-...
cos(x(11))*(sin(x(13))*cos(x(8)-x(14))+sin(x(15))*cos(x(8)-x(16)))));
c4=cos(x(1))*(sin(x(5))*(sin(x(9))*cos(x(6)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(6)-x(12))*(cos(x(13))+cos(x(15))))+...
sin(x(7))*(sin(x(11))*cos(x(8)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(8)-x(10))*(cos(x(13))+cos(x(15)))))+...
cos(x(3))*(sin(x(5))*(sin(x(11))*cos(x(6)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(6)-x(10))*(cos(x(13))+cos(x(15))))-...
sin(x(7))*(sin(x(9))*cos(x(8)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(8)-x(12))*(cos(x(13))+cos(x(15)))));
c5=sin(x(1))*(cos(x(5))*(cos(x(9))*(sin(x(13))*cos(x(2)-x(14))-sin(x(15))*cos(x(2)-x(16)))-...
cos(x(11))*(sin(x(13))*cos(x(2)-x(14))+sin(x(15))*cos(x(2)-x(16))))+...
cos(x(7))*(cos(x(11))*(sin(x(15))*cos(x(2)-x(16))-sin(x(13))*cos(x(2)-x(14)))-...
cos(x(9))*(sin(x(13))*cos(x(2)-x(14))+sin(x(15))*cos(x(2)-x(16)))))+...
sin(x(3))*(cos(x(5))*(cos(x(11))*(sin(x(15))*cos(x(4)-x(16))-sin(x(13))*cos(x(4)-x(14)))-...
cos(x(9))*(sin(x(13))*cos(x(4)-x(14))+sin(x(15))*cos(x(4)-x(16))))-...
cos(x(7))*(cos(x(9))*(sin(x(13))*cos(x(4)-x(14))-sin(x(15))*cos(x(4)-x(16)))-...
cos(x(11))*(sin(x(13))*cos(x(4)-x(14))+sin(x(15))*cos(x(4)-x(16)))));
c6=sin(x(1))*(cos(x(5))*(sin(x(9))*cos(x(2)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(2)-x(12))*(cos(x(13))+cos(x(15))))+...
cos(x(7))*(sin(x(11))*cos(x(2)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(2)-x(10))*(cos(x(13))+cos(x(15)))))+...
sin(x(3))*(cos(x(5))*(sin(x(11))*cos(x(4)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(4)-x(10))*(cos(x(13))+cos(x(15))))-...
cos(x(7))*(sin(x(9))*cos(x(4)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(4)-x(12))*(cos(x(13))+cos(x(15)))));
c7=sin(x(1))*(sin(x(5))*cos(x(2)-x(6))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15))))-...
sin(x(7))*cos(x(2)-x(8))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15)))))+...
sin(x(3))*(sin(x(5))*cos(x(4)-x(6))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15))))-...
sin(x(7))*cos(x(4)-x(8))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15)))));
A2=2*a*b;
A3=2*a*c;
A4=2*b*c;
A5=2*a*d;
A6=2*b*d;
A7=2*c*d;
f1=c1+A2*c2+A3*c3+A4*c4+A5*c5+A6*c6+A7*c7;
f=-(f1^2);
my main file of the code
clear
close
clc
%x=[x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)]; % angles;
lb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
ub=[pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi];
options = optimoptions(#fmincon,'TolX',10^-12,'MaxIter',1500,'MaxFunEvals',10^8,'Algorithm','sqp','TolFun',10^-8);
a=0:0.1:1;
b=0:0.1:1;
c=0:0.1:1;
w=NaN(length(a),length(b),length(c));
ww=NaN(length(a),length(b),length(c));
www=NaN(length(a),length(c));
for k=1:100
x0=rand([1,16]).*ub*.9986;%7976
for i=1:length(a)
for j=1:length(b)
for l=1:length(c)
dhelp=1-(a(i)^2)-(b(j)^2)-(c(l)^2);
if (dhelp>0 || dhelp==0)
d=sqrt(dhelp);
[~,fval]=fmincon(#(x)W4qubit(x,a(i),b(j),c(l),d),x0,[],[],[],[],lb,ub,[],options);
w(i,j,l)=sqrt(-fval);
else
w(i,j,l)=nan;
end
ww=max(w,ww);
end
end
end
end
www=max(ww,[],3);
yy=b.^2;xx=a.^2;zz=c.^2;
meshc(xx,yy,www)
grid on
zlabel('\fontname{Times New Roman} M_{max}')
xlabel('\fontname{Times New Roman}\alpha^2')
ylabel('\fontname{Times New Roman}\gamma^2')
%title('fontname{Times New Roman} Maximum of the Svetlichny operator. Method 1 (alpha|0001>+beta|0010>+gamma|1000>)')
Not sure, but doesn't
plot(www,[xx;yy;zz]);
do the job for you? I do not have the optimization toolbox, so I can't test your script. But in principle, this should work.
My code describes a FSM to control a traffic light. There are four states, each with a different
duration.
Whenever the counter equals 1, the counter needs one more clock to change to the next value. For example, at state1, counter is programmed to count from 4 to 1. Every value should only take one clock to
change to the next, when it does, the state is changed to the next state. But when counter equals 1, it takes two clocks to change.
My program is as follows. The counter is implemented at the bottom of the always block:
module HW3(times,A,B,clk,rst,iHand,iChang,s1);
input clk,rst;
output reg [2:0]A,B;
wire oclk;//new freq
reg [2:0] count1,count2,count3,count4;//count times
reg [2:0]times;
reg temp;//control the switch
parameter [2:0]state1=3'd0,state2=3'd1,state3=3'd2,state4=3'd3;
always#(posedge clk or negedge rst )
begin
if(!rst)
begin
s1<=state1;
A<=3'b0;
B<=3'b0;
count1<=3'd4;
count2<=3'd2;
count3<=3'd3;
count4<=3'd2;
temp<=1'b1;
end
else
begin
if(temp==1)
begin
temp<=1'b0;
case(s1)
state1:
begin
times<=count1;
A<=3'b001;
B<=3'b100;
s1<=state2;
end
state2:
begin
times<=count2;
A<=3'b010;
B<=3'b100;
s1<=state3;
end
state3:
begin
times<=count3;
A<=3'b100;
B<=3'b001;
s1<=state4;
end
state4:
begin
times<=count4;
A<=3'b100;
B<=3'b010;
s1<=state1;
end
default:
begin
A<=3'b000;
B<=3'b000;
end
endcase
end
else
begin
if(times>1)
times<=times-1;
else if(times==1)
begin
temp<=1'b1;//can't count averagely
end
end
end
end
endmodule
Modify the code at the bottom of the always clock as:
if(times>2)
times<=times-1;
else if(times==2)
begin
times=times-1;
temp<=1'b1;//can't count averagely
end
Just let the times counts to 2 ,because if let it count to 1, the program will again enter the if
block in the next clock but doesnt change the value of times ,and make the value of times=1 unchanged
for one more clock
my matlab code bellow takes a very long time to run. How could I compose it to take just seconds to run? I would be thankful if you could help me. parameters i, k_hat and alpha are constants.
%%%%%%%%%%%%%%%%%%%
p_desired=zeros(1,length(alpha));
p_ICI=zeros(1,length(alpha));
p_MUI=zeros(1,length(alpha));
tic
for ss=1:length(alpha)
uN=2*pi/N*Ts*abs(sin(alpha(ss)));
uM=2*pi/M*Ts*abs(sin(alpha(ss)));
for j=0:M/N-1
for k=0:N-1
for q=0:N-1
for qq=0:N-1
for q_hat=0:N-1
for qq_hat=0:N-1
for n=0:M-1
for m=-Ng:M-1
for n_hat=0:N-1
for m_hat=-Ng:N-1
if (n-m-n_hat+m_hat==0)
if (i==j && k==k_hat)
p_desired(ss)=p_desired(ss)+((sin(-alpha(ss))-1i*cos(-alpha(ss)))/N)^.5*exp(1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(1i/2*q^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*q*k_hat/N)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/N)^.5*exp(-1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(-1i/2*q_hat^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*q_hat*k_hat/N)...
* ((sin(alpha(ss))-1i*cos(alpha(ss)))/N)^.5*exp(1i/2*qq^2*cot(alpha(ss))*uN^2)*exp(1i/2*k_hat^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*qq*k_hat/N)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/N)^.5*exp(-1i/2*qq_hat^2*cot(alpha(ss))*uN^2)*exp(-1i/2*k_hat^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*qq_hat*k_hat/N)...
*((sin(alpha(ss))-1i*cos(alpha(ss)))/M)^.5*exp(1i/2*(q+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(1i/2*n^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*(q+N*(i-1))*n/M)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/M)^.5*exp(-1i/2*(q_hat+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(-1i/2*n_hat^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*(q_hat+N*(i-1))*n_hat/M)...
*((sin(-alpha(ss))-1i*cos(-alpha(ss)))/M)^.5*exp(1i/2*m^2*cot(-alpha(ss))*uM^2)*exp(1i/2*(qq+N*(i-1))^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*m*(qq+N*(i-1))/M)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/M)^.5*exp(-1i/2*m_hat^2*cot(-alpha(ss))*uM^2)*exp(-1i/2*(qq_hat+N*(i-1))^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*m_hat*(qq_hat+N*(i-1))/M)...
*exp(1i*2*pi/M*(n-n_hat)*e)*exp(-abs(n-m)/gamma)* besselj(0,2*pi*abs(n-n_hat)*fd);
elseif (i==j && k~=k_hat)
p_ICI(ss)=p_ICI(ss)+((sin(-alpha(ss))-1i*cos(-alpha(ss)))/N)^.5*exp(1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(1i/2*q^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*q*k_hat/N)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/N)^.5*exp(-1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(-1i/2*q_hat^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*q_hat*k_hat/N)...
* ((sin(alpha(ss))-1i*cos(alpha(ss)))/N)^.5*exp(1i/2*qq^2*cot(alpha(ss))*uN^2)*exp(1i/2*k^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*qq*k/N)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/N)^.5*exp(-1i/2*qq_hat^2*cot(alpha(ss))*uN^2)*exp(-1i/2*k^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*qq_hat*k/N)...
*((sin(alpha(ss))-1i*cos(alpha(ss)))/M)^.5*exp(1i/2*(q+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(1i/2*n^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*(q+N*(i-1))*n/M)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/M)^.5*exp(-1i/2*(q_hat+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(-1i/2*n_hat^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*(q_hat+N*(i-1))*n_hat/M)...
*((sin(-alpha(ss))-1i*cos(-alpha(ss)))/M)^.5*exp(1i/2*m^2*cot(-alpha(ss))*uM^2)*exp(1i/2*(qq+N*(i-1))^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*m*(qq+N*(i-1))/M)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/M)^.5*exp(-1i/2*m_hat^2*cot(-alpha(ss))*uM^2)*exp(-1i/2*(qq_hat+N*(i-1))^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*m_hat*(qq_hat+N*(i-1))/M)...
*exp(1i*2*pi/M*(n-n_hat)*e)*exp(-abs(n-m)/gamma) *besselj(0,2*pi*abs(n-n_hat)*fd);
elseif (i~=j)
p_MUI(ss)=p_MUI(ss)+((sin(-alpha(ss))-1i*cos(-alpha(ss)))/N)^.5*exp(1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(1i/2*q^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*q*k_hat/N)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/N)^.5*exp(-1i/2*k_hat^2*cot(-alpha(ss))*uN^2)*exp(-1i/2*q_hat^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*q_hat*k_hat/N)...
* ((sin(alpha(ss))-1i*cos(alpha(ss)))/N)^.5*exp(1i/2*qq^2*cot(alpha(ss))*uN^2)*exp(1i/2*k^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*qq*k/N)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/N)^.5*exp(-1i/2*qq_hat^2*cot(alpha(ss))*uN^2)*exp(-1i/2*k^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*qq_hat*k/N)...
*((sin(alpha(ss))-1i*cos(alpha(ss)))/M)^.5*exp(1i/2*(q+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(1i/2*n^2*cot(alpha(ss))*Ts^2)*exp(-1i*2*pi*(q+N*(i-1))*n/M)...
*((sin(alpha(ss))+1i*cos(alpha(ss)))/M)^.5*exp(-1i/2*(q_hat+N*(i-1))^2*cot(alpha(ss))*uM^2)*exp(-1i/2*n_hat^2*cot(alpha(ss))*Ts^2)*exp(+1i*2*pi*(q_hat+N*(i-1))*n_hat/M)...
*((sin(-alpha(ss))-1i*cos(-alpha(ss)))/M)^.5*exp(1i/2*m^2*cot(-alpha(ss))*uM^2)*exp(1i/2*(qq+N*(j-1))^2*cot(-alpha(ss))*Ts^2)*exp(-1i*2*pi*m*(qq+N*(j-1))/M)...
*((sin(-alpha(ss))+1i*cos(-alpha(ss)))/M)^.5*exp(-1i/2*m_hat^2*cot(-alpha(ss))*uM^2)*exp(-1i/2*(qq_hat+N*(j-1))^2*cot(-alpha(ss))*Ts^2)*exp(+1i*2*pi*m_hat*(qq_hat+N*(j-1))/M)...
*exp(1i*2*pi/M*(n-n_hat)*e)*exp(-abs(n-m)/gamma)* besselj(0,2*pi*abs(n-n_hat)*fd);
end
else
p_desired(ss)=p_desired(ss);
p_ICI(ss)=p_ICI(ss);
p_MUI(ss)=p_MUI(ss);
end
end
end
end
end
end
end
end
end
end
end
end
toc
Remove "for ss=1:length(alpha)" and corresponding "end"
Convert all "alpha(ss)" to "alpha"
Convert all "p_desired(ss)" to "p_desired"
Convert all "p_ICI(ss)" to "p_ICI"
Convert all "p_MUI(ss)" to "p_MUI"
Convert all "*", "/" and "^" to ".*", './' and ".^" respectively.
Convert "elseif (i~=j)" to "else"
Remove below code:
else
p_desired(ss)=p_desired(ss);
p_ICI(ss)=p_ICI(ss);
p_MUI(ss)=p_MUI(ss);