Category: Matlab
Category Archives: Matlab
Wrong sine plot when styling it
I was playing with the tutorial of Matlab. I’ve written this code:
x = linspace(0, 2*pi);
y = sin(x);
plot(x, y)
And I obtain the right plot:
But then I use the following command:
plot(x, y, "r–")
And I obtain this weird plot:
What I’m doing wrong?I was playing with the tutorial of Matlab. I’ve written this code:
x = linspace(0, 2*pi);
y = sin(x);
plot(x, y)
And I obtain the right plot:
But then I use the following command:
plot(x, y, "r–")
And I obtain this weird plot:
What I’m doing wrong? I was playing with the tutorial of Matlab. I’ve written this code:
x = linspace(0, 2*pi);
y = sin(x);
plot(x, y)
And I obtain the right plot:
But then I use the following command:
plot(x, y, "r–")
And I obtain this weird plot:
What I’m doing wrong? plot, error MATLAB Answers — New Questions
How to rearrange String Data within table relative to one Column of Data.
Hello,
I have a table with 80X10. The first Variable (Var 1) has text Data, Variable 8 (Relavent Data), Variable 9 (parameter List), Variable 10 (GPP_Names). Var1 to Var8 Imported from File A and Var 9, Var10 (Parameter_List & Gpp_Names) Imported from another.
Both Contatinated (horzcat) and put together in one table Common_Data_1. As in the attached picture.
Var 1 & Var 9 (Parameter_List) are exactly same text. But I am unable to arrange it to match each other.
Var9 (Parameter_List) & Var 10 (Gpp_Names) are alligned Perfectly.
I would like to extract Var 1,Var8, Parameter_List,GPP_Names data that perfectly aligned.
1) Should I match the text pattern before Concatinating them into one Table?
2) How could I use sortrows or rowfun or other functions to arrange this data?
Any help or suggestion would be of great help.
Thanks
SaiHello,
I have a table with 80X10. The first Variable (Var 1) has text Data, Variable 8 (Relavent Data), Variable 9 (parameter List), Variable 10 (GPP_Names). Var1 to Var8 Imported from File A and Var 9, Var10 (Parameter_List & Gpp_Names) Imported from another.
Both Contatinated (horzcat) and put together in one table Common_Data_1. As in the attached picture.
Var 1 & Var 9 (Parameter_List) are exactly same text. But I am unable to arrange it to match each other.
Var9 (Parameter_List) & Var 10 (Gpp_Names) are alligned Perfectly.
I would like to extract Var 1,Var8, Parameter_List,GPP_Names data that perfectly aligned.
1) Should I match the text pattern before Concatinating them into one Table?
2) How could I use sortrows or rowfun or other functions to arrange this data?
Any help or suggestion would be of great help.
Thanks
Sai Hello,
I have a table with 80X10. The first Variable (Var 1) has text Data, Variable 8 (Relavent Data), Variable 9 (parameter List), Variable 10 (GPP_Names). Var1 to Var8 Imported from File A and Var 9, Var10 (Parameter_List & Gpp_Names) Imported from another.
Both Contatinated (horzcat) and put together in one table Common_Data_1. As in the attached picture.
Var 1 & Var 9 (Parameter_List) are exactly same text. But I am unable to arrange it to match each other.
Var9 (Parameter_List) & Var 10 (Gpp_Names) are alligned Perfectly.
I would like to extract Var 1,Var8, Parameter_List,GPP_Names data that perfectly aligned.
1) Should I match the text pattern before Concatinating them into one Table?
2) How could I use sortrows or rowfun or other functions to arrange this data?
Any help or suggestion would be of great help.
Thanks
Sai text match alligment, table, sortrows, rowfunc MATLAB Answers — New Questions
How to efficiently solve a system with an infinity number of solutions?
Consider A to be a square matrix of size n and S to be a symmetric square matrix of size n. I know the first row of A and I know each element in S. I need to find the remaining elements (from row 2 to row n) of A such that A’A = S. This system allows an infinite number of solutions and I am not interested in a particular solution (any of them is fine). Does it exist an efficient procedure to find one among these solutions? In other words, I do not want to use an "fsolve" procedure because it is computationally too demanding. I would like to find a solution in the same spirit of chol(S)’*chol(S) = S. Nevertheless, chol(S) does not work because does not guarantee that the first row of A is the one I need. For another similar problem, I remember that null(A(1,:)) was useful. The problem is that [A(1,:); null(A(1,:))]’*[A(1,:); null(A(1,:))] = eye(n) and I need the right-hand side to be equal to S (instead of eye(n)).
I hope the problem is clear. Many thanks for the help.Consider A to be a square matrix of size n and S to be a symmetric square matrix of size n. I know the first row of A and I know each element in S. I need to find the remaining elements (from row 2 to row n) of A such that A’A = S. This system allows an infinite number of solutions and I am not interested in a particular solution (any of them is fine). Does it exist an efficient procedure to find one among these solutions? In other words, I do not want to use an "fsolve" procedure because it is computationally too demanding. I would like to find a solution in the same spirit of chol(S)’*chol(S) = S. Nevertheless, chol(S) does not work because does not guarantee that the first row of A is the one I need. For another similar problem, I remember that null(A(1,:)) was useful. The problem is that [A(1,:); null(A(1,:))]’*[A(1,:); null(A(1,:))] = eye(n) and I need the right-hand side to be equal to S (instead of eye(n)).
I hope the problem is clear. Many thanks for the help. Consider A to be a square matrix of size n and S to be a symmetric square matrix of size n. I know the first row of A and I know each element in S. I need to find the remaining elements (from row 2 to row n) of A such that A’A = S. This system allows an infinite number of solutions and I am not interested in a particular solution (any of them is fine). Does it exist an efficient procedure to find one among these solutions? In other words, I do not want to use an "fsolve" procedure because it is computationally too demanding. I would like to find a solution in the same spirit of chol(S)’*chol(S) = S. Nevertheless, chol(S) does not work because does not guarantee that the first row of A is the one I need. For another similar problem, I remember that null(A(1,:)) was useful. The problem is that [A(1,:); null(A(1,:))]’*[A(1,:); null(A(1,:))] = eye(n) and I need the right-hand side to be equal to S (instead of eye(n)).
I hope the problem is clear. Many thanks for the help. matrix algebra, cholesky, null MATLAB Answers — New Questions
how do I use filtfilt on a GPU?
Hello,
I am trying to get filtfilt to run on a GPU and I’m unable to get the formatting right (I think).
Eventually, I’d like to calculate phase-amplitude coupling over a wide range of frequencies with a zero-phase filter.This ends up taking a very long time and the slowest step so far seems to be the bandpass filtering of my signals, so I’d like to run those on my GPU instead of the CPU. I’m basing my filter design on eegfilt.m from the EEGLab toolbox.
I’m trying to get my code to run with a small EEG snippet first. I’ve replaced the real signal with random numbers for this question, but I can share some real signal later if that helps.
I have tried two different ways of calling filtfilt with arrayfun and am receiving two different error messages:
Attempt1: I tried to use arrayfun in the way I’d normally use it (on a non-gpuArray). This gives ‘Use of functional workspace is not supported.’
In attempt 2: when I try to use arrayfun in a way that more closely resembles the GPU-related documentation, I get ‘Indexing is not supported’.
Is it possible to use filtfilt with a GPU array at all? Can someone please tell me what stupid thing I’m doing wrong?
srate = 1000;
locutoff = 10;
hicutoff = 12;
testbit = rand(12*srate,1) %testbit = EEG(1:12*srate);
%filter settings
minfac = 3; % this many (lo)cutoff-freq cycles in filter
min_filtorder = 15; % minimum filter length
filtorder = minfac*fix(srate/hicutoff);
if filtorder < min_filtorder
filtorder = min_filtorder;
end
filtwts = fir1(filtorder, [locutoff, hicutoff]./(srate/2));
% without GPU
filtsig1 = filtfilt(filtwts,1,testbit’);
%attempt 1 with GPU (does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@(x) filtfilt(filtwts,1,x),testbit);
%attempt 2 with GPU (also does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@filtfilt, filtwts,1,testbit);Hello,
I am trying to get filtfilt to run on a GPU and I’m unable to get the formatting right (I think).
Eventually, I’d like to calculate phase-amplitude coupling over a wide range of frequencies with a zero-phase filter.This ends up taking a very long time and the slowest step so far seems to be the bandpass filtering of my signals, so I’d like to run those on my GPU instead of the CPU. I’m basing my filter design on eegfilt.m from the EEGLab toolbox.
I’m trying to get my code to run with a small EEG snippet first. I’ve replaced the real signal with random numbers for this question, but I can share some real signal later if that helps.
I have tried two different ways of calling filtfilt with arrayfun and am receiving two different error messages:
Attempt1: I tried to use arrayfun in the way I’d normally use it (on a non-gpuArray). This gives ‘Use of functional workspace is not supported.’
In attempt 2: when I try to use arrayfun in a way that more closely resembles the GPU-related documentation, I get ‘Indexing is not supported’.
Is it possible to use filtfilt with a GPU array at all? Can someone please tell me what stupid thing I’m doing wrong?
srate = 1000;
locutoff = 10;
hicutoff = 12;
testbit = rand(12*srate,1) %testbit = EEG(1:12*srate);
%filter settings
minfac = 3; % this many (lo)cutoff-freq cycles in filter
min_filtorder = 15; % minimum filter length
filtorder = minfac*fix(srate/hicutoff);
if filtorder < min_filtorder
filtorder = min_filtorder;
end
filtwts = fir1(filtorder, [locutoff, hicutoff]./(srate/2));
% without GPU
filtsig1 = filtfilt(filtwts,1,testbit’);
%attempt 1 with GPU (does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@(x) filtfilt(filtwts,1,x),testbit);
%attempt 2 with GPU (also does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@filtfilt, filtwts,1,testbit); Hello,
I am trying to get filtfilt to run on a GPU and I’m unable to get the formatting right (I think).
Eventually, I’d like to calculate phase-amplitude coupling over a wide range of frequencies with a zero-phase filter.This ends up taking a very long time and the slowest step so far seems to be the bandpass filtering of my signals, so I’d like to run those on my GPU instead of the CPU. I’m basing my filter design on eegfilt.m from the EEGLab toolbox.
I’m trying to get my code to run with a small EEG snippet first. I’ve replaced the real signal with random numbers for this question, but I can share some real signal later if that helps.
I have tried two different ways of calling filtfilt with arrayfun and am receiving two different error messages:
Attempt1: I tried to use arrayfun in the way I’d normally use it (on a non-gpuArray). This gives ‘Use of functional workspace is not supported.’
In attempt 2: when I try to use arrayfun in a way that more closely resembles the GPU-related documentation, I get ‘Indexing is not supported’.
Is it possible to use filtfilt with a GPU array at all? Can someone please tell me what stupid thing I’m doing wrong?
srate = 1000;
locutoff = 10;
hicutoff = 12;
testbit = rand(12*srate,1) %testbit = EEG(1:12*srate);
%filter settings
minfac = 3; % this many (lo)cutoff-freq cycles in filter
min_filtorder = 15; % minimum filter length
filtorder = minfac*fix(srate/hicutoff);
if filtorder < min_filtorder
filtorder = min_filtorder;
end
filtwts = fir1(filtorder, [locutoff, hicutoff]./(srate/2));
% without GPU
filtsig1 = filtfilt(filtwts,1,testbit’);
%attempt 1 with GPU (does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@(x) filtfilt(filtwts,1,x),testbit);
%attempt 2 with GPU (also does not work)
testbit = gpuArray(testbit’);
filtsig2 = arrayfun(@filtfilt, filtwts,1,testbit); filtfilt, arrayfun, gpuarray, matlab2019b MATLAB Answers — New Questions
How to code this summation equation?
I need to calculate a parameter called SigmaI and BER, where the equation is
Here I is a 512*512 matrix. But the value of SigmaI that I calculated is not same as reported values.I think there is some error in writing the code. Also I need to calculate SigmaI for each F points (F is 1*757 matrix), but what I get is the value of SigmaI at the last point of F only. i.e, I need to generated SigmaI as 1*757 matrix. I am confused how to include it in the for loop. Similary BER also needed as a 1*757 matrix. Can anyone help me to get the right answer. The code is as follows,
clc;close all;clear all;
lambda = 532;
k = 2*pi/lambda;
z=linspace(1,757,757);
z_diff = (diff(z)) ;
z_diff = [0 z_diff];
tilt_angle=10;
beta=(pi/180)*tilt_angle;
Lx = 0.1;
Ly = Lx;
Nx = 512;
Ny = Nx ;
dx = Lx/Nx;
dy = Ly/Ny;
x = (-Nx/2:Nx/2-1)*dx;
y = (-Ny/2:Ny/2-1)*dy;
[X,Y] = meshgrid(x,y);
r = sqrt(X.^2 + Y.^2);
kx = meshgrid(-Nx/2:Nx/2-1)/(Nx.*dx);
ky = meshgrid(-Ny/2:Ny/2-1)/(Ny.*dy);
kz = ones(Nx);
Kx=cos(beta).*kx + sin(beta).*kz;
Ky=ky;
Kz=-sin(beta).*kx + cos(beta).*kz;
K2 = Kx.^2 + Ky.^2 + Kz.^2;
delfx = 1/(Lx);
delfy = delfx;
R = randn(Nx,Ny) ;
R = R – mean(R(:,:));
R = R/std(R(:,:));
Phi = [2.50310494762771e-07 2.50946965543003e-07 4.74127533715154e-07 5.24210357233832e-06 2.42362427581638e-07 1.42653443399616e-07 5.16930235276850e-07 9.04590700562310e-07 2.29541191637123e-06 3.60105794008093e-07 9.17845719860523e-08 2.50390367004531e-07 1.09738615765455e-06 1.00311041468925e-06 6.50810613011221e-08 3.02640252523566e-07 5.31047019902531e-07 1.80313245178286e-06 3.04099822876624e-06 1.47008194185741e-07 4.08290582950848e-08 3.82118426499270e-06 5.29334397036188e-07 4.87810778598663e-06 1.18782521297988e-06 1.16666772914768e-06 1.69778706192608e-06 7.67426466736916e-06 5.27799451227444e-06 4.23216916272082e-07 2.66828750584071e-05 2.46205729358867e-06 2.80169965568206e-06 2.97378024567976e-07 2.21170607901861e-07 3.41285818450589e-07 3.85275104621375e-08 4.05141179263807e-07 1.17629321652161e-06 4.95233464403551e-06 1.80125151270180e-06 2.81483058944610e-07 1.24528365857859e-05 6.86781782456521e-06 2.95828059847895e-06 1.27035361174474e-06 6.34388599513081e-07 2.32012818083199e-06 2.81784487117724e-06 1.46096455213802e-06 1.60178082889894e-06 1.94791694377124e-07 6.35459501021705e-08 8.30940388112504e-08 2.53354933929590e-07 4.31247522543152e-06 9.63180625859285e-07 8.03726503455623e-07 2.98282116276067e-07 9.25402679823575e-08 1.61856374619784e-07 1.73242501417858e-07 2.31570160754109e-07 1.78600321810053e-07 1.25598618058698e-07 1.63418364388577e-06 1.02774042441542e-06 8.32018926678718e-08 2.53586554087675e-07 2.53508325030189e-07 4.07413642129177e-08 2.42096085408459e-07 5.91587468209778e-07 1.27761778023523e-07 1.65773731666773e-07 1.79565395840267e-07 3.78521468221561e-07 1.21471607158554e-07 3.25378687175317e-07 1.25569084575180e-07 5.49035746100893e-08 4.07733632799329e-08 4.79103771763424e-07 3.27135102365317e-07 2.10496092551324e-07 1.33641668807187e-06 1.68227872575447e-06 1.52265748820018e-06 2.53683706505161e-07 1.25630494723704e-07 1.12347756326375e-06 2.53692684133802e-07 2.10500428113819e-07 2.52934873659000e-07 6.77249701528946e-07 2.95386782896753e-07 3.16617852613830e-07 3.59879226900604e-07 2.81244834536819e-07 2.35438339516804e-07 3.40806542459708e-07 6.44683615098099e-08 5.05945401350734e-07 2.57387924440325e-07 7.82108421793457e-08 2.52513556939930e-07 7.41154472489689e-08 8.95664707278605e-08 3.44823854262242e-07 2.57498619329261e-07 2.07939465354519e-06 7.18570183290631e-07 3.25198024230522e-07 2.11933525065655e-07 8.30783371984955e-08 1.65710628194624e-07 5.48396993890243e-08 5.95342783012939e-08 2.28819020334242e-07 1.99067722101735e-07 2.40425372248607e-07 2.51916559208949e-07 2.98446361528618e-07 2.82958505602994e-07 2.10599141757522e-07 4.60997674322361e-08 2.59856693650578e-07 1.47642122461920e-07 3.93574284250877e-07 3.94729289526600e-08 6.37347851352551e-08 2.51536627057736e-07 2.28438571372065e-07 1.90144303446780e-07 4.73626330414131e-08 6.44142268235402e-08 1.72106272576708e-06 1.70721924857358e-06 2.94643811973548e-07 3.55943119776846e-08 9.36518317402136e-08 4.31201179335937e-08 1.56428758776995e-07 3.19975996745435e-07 3.34275554966361e-07 1.20064760586921e-06 4.30984033789707e-07 2.15616245567332e-07 3.03074660779611e-07 3.29934827134432e-07 -2.24864187842034e-08 2.33412514429474e-07 3.21092520408291e-07 3.38617740923693e-07 6.04579881670076e-07 1.91481555229955e-07 9.38472397526705e-08 6.13052684855612e-07 3.97260343618278e-06 2.45355935394897e-07 3.47585309986832e-07 3.38923893338132e-07 2.20926360286704e-07 5.25446559955282e-07 2.84158336921376e-07 4.04755442008443e-07 3.35541338245773e-07 3.76856346223440e-07 2.75568777774655e-07 2.09025928742013e-07 7.10170870233622e-08 2.95787195332815e-07 5.59078661720798e-07 2.51150081156080e-07 4.02707325242296e-08 8.24148001852386e-08 2.57363940284162e-07 3.55816103375846e-07 3.95777597622744e-07 3.27993323594138e-07 3.52690891300866e-07 3.52278318886910e-07 5.06712192595194e-08 1.23808524289852e-07 8.39347385990663e-07 2.02892942754780e-07 7.97641133582245e-08 3.64530615247902e-07 9.11185642215493e-07 2.44511041473120e-07 3.24963966176285e-07 1.11685979674259e-07 2.86261990645848e-07 3.75634147009314e-08 2.16925989302430e-07 3.84116828662608e-07 2.71791109589261e-07 1.06845659312697e-07 2.02225581949648e-07 3.02535099485185e-07 3.11957552477906e-08 9.15881915538412e-08 9.18891121954120e-07 3.70106500980225e-07 2.25779726927071e-07 2.86067288473873e-07 5.66382866246259e-07 4.26632108086086e-07 4.53045634671475e-07 1.17973378714372e-06 3.40969918417227e-07 2.48643473538260e-07 2.64505922988546e-07 2.38444406096982e-07 3.47101823144428e-07 3.37625374999722e-07 3.20790426924069e-07 5.02178252920690e-08 1.73576015527609e-07 8.57402376593969e-07 1.80131811857122e-07 2.76964595681315e-07 2.14838038341036e-07 2.21053263051776e-07 1.59406260405821e-07 4.59614264881235e-08 3.78789455759776e-07 2.58966590318316e-07 7.75696011578299e-08 3.39990416320565e-07 3.24572509489827e-07 3.52020828992088e-08 6.49912862168267e-08 2.22828739301052e-07 2.13473046057573e-07 1.70720547021041e-07 2.19582224668132e-07 2.05914598785446e-07 1.14899310738254e-06 1.03415047080757e-07 1.89177690522258e-06 2.24175047702725e-07 3.76150153666139e-07 9.18124634120261e-08 2.27678254839140e-07 8.61346207114181e-08 3.38947999645138e-06 1.71880093129416e-07 2.22461873169689e-07 3.72427593494344e-08 6.76102058093114e-08 1.13163515787091e-06 7.04052219453715e-07 3.28310827940334e-07 2.12060821359437e-07 2.68576701610855e-07 2.04744061114503e-07 1.14622616867334e-07 4.35675529886048e-08 5.29665131717990e-08 3.50574437154752e-08 5.32920831968263e-08 1.04801149974382e-07 2.08316009852988e-07 2.77349913208742e-07 1.48756450473382e-07 3.78517042358300e-07 1.19222278136494e-07 4.57902170141890e-08 2.03249187200450e-07 9.32437812713631e-08 6.61503340988668e-07 1.01572927594225e-06 3.26294032932256e-07 2.26313604682662e-07 7.01012285236915e-08 7.61666326540900e-08 4.16954886967803e-08 4.41719683698357e-08 4.02549730011751e-08 4.41603434482274e-08 3.50371730851861e-08 3.00718061774876e-07 3.50372423542925e-08 5.32741630316562e-08 2.09046711312522e-07 3.75611845531339e-06 2.26535469768828e-07 4.62710159517236e-07 5.55357457448765e-07 4.16702305525217e-07 2.05922476618442e-07 2.06490274401431e-07 2.33754328058605e-07 1.66615319203810e-07 2.13390792614979e-07 2.54792444311713e-07 4.20241426628409e-07 6.95047952441784e-07 6.02254152247896e-07 1.56218004764843e-07 1.99836446669293e-07 1.62974708502310e-07 2.93420921132526e-07 1.67909832369442e-07 1.53692619622575e-07 8.89709805825161e-08 1.64148574413349e-07 1.82871518257336e-07 1.99566615308843e-07 1.59784291140960e-07 1.87893662090374e-07 2.77364481028229e-07 1.10443572547260e-07 2.18556580353372e-07 1.83932131011210e-07 7.94652011731045e-08 2.43919458395486e-07 1.59781205439559e-07 1.94642054497664e-07 1.29989372686070e-07 1.90910393259075e-07 2.84452061601644e-07 3.30006526167654e-07 1.93485493531741e-07 2.40209860863182e-07 4.15333943239071e-07 2.91343651778087e-07 2.58377576473351e-07 1.81274762632482e-07 1.88893039486970e-07 2.19428417763272e-07 2.20994023873646e-07 2.27950728874121e-07 1.64400439994395e-07 1.00341668297253e-07 1.67577483763212e-07 5.61980802260245e-08 3.04539633123467e-08 3.19018898206730e-08 3.89504322796163e-08 3.19941498021468e-07 5.41874921040340e-06 1.01776790218898e-06 1.29079721421378e-06 5.77887058141474e-07 2.79939362285509e-07 5.55989804582382e-08 2.11144624551603e-07 5.73140726411827e-08 5.35992572193921e-08 2.80066251579433e-07 1.76964657359828e-07 3.25199602895421e-07 2.18271466195228e-07 1.80628024038326e-07 4.69550563668357e-08 1.48055689005769e-07 1.82317859358405e-07 1.33063533148151e-07 2.62672490298873e-08 2.52416541944235e-08 2.08244390466210e-07 3.06261128674104e-07 2.18183988930487e-07 1.32114003617060e-07 3.13731744862144e-07 2.78980205382911e-07 2.42110700965470e-08 1.28818767334643e-07 3.48416502648141e-07 1.43250842379859e-07 2.58790299254369e-08 2.36803673262810e-08 2.54679999490770e-08 1.53423624973069e-07 2.11044574009824e-07 2.45219073821534e-08 5.40329423903049e-08 4.07828910547019e-08 2.86866659397290e-08 5.74108869690081e-08 3.17780519921456e-08 2.89072270765441e-07 6.46668413187508e-08 3.89801393203052e-07 1.62322978572959e-07 2.69026419637955e-07 4.76120100475985e-07 5.32185045407108e-07 1.57575408820348e-07 2.08858600548085e-07 1.87565977660685e-07 2.01108310997773e-07 3.95620143987532e-08 5.24866345380986e-08 8.64930520826212e-08 9.74072997804584e-07 2.54439638933078e-08 1.00154777975012e-07 9.42429455464106e-07 2.23088555779751e-07 2.02097796370716e-07 1.99163165408265e-07 9.26536634692885e-08 1.31298738607173e-07 1.97726692783641e-07 2.28150683478771e-07 2.17170907865184e-07 2.69677497220439e-08 1.54765400027711e-07 6.26255760215395e-08 1.46771827369792e-07 1.81515822529873e-07 1.72918459779846e-07 8.15990146285526e-08 9.85514009220808e-08 7.03396855430348e-07 5.93657045438661e-07 1.51834395684521e-07 9.76927764035926e-08 1.18527867299870e-07 2.71435324116586e-08 5.68571003566081e-08 1.65983256102705e-07 2.29129793972797e-07 5.88646431511064e-08 3.08684402204026e-05 2.38265317337181e-06 4.30752744717656e-07 1.04689461805175e-07 2.32270648752108e-07 6.07211466407868e-07 1.95341105985221e-08 7.38231690963101e-08 1.95129857199575e-07 4.01671898332107e-08 4.75072551754564e-08 2.49046064060719e-06 1.78142428447807e-07 2.60935684174315e-07 4.29594269700864e-08 1.14070714922750e-07 5.26390027271695e-08 6.74132420131039e-08 2.11045265009953e-07 7.27021148761358e-07 2.83886081059763e-07 2.76343292567963e-08 1.61294742863238e-07 1.83304573271511e-07 2.45251911632262e-07 9.18095053702886e-07 9.40457085677553e-07 2.90451584499496e-07 1.04003175628026e-07 1.08284695915254e-07 5.44402482199441e-08 2.02578013696944e-08 5.88615942025308e-08 1.04406254724335e-07 1.20598226687063e-07 5.71264670628078e-07 3.15144191075623e-07 2.23052176438872e-08 2.98936409995515e-08 2.92428609360162e-07 2.47505388371339e-07 2.72866577624107e-07 2.69881858030521e-07 1.85519336468060e-07 2.56402576998181e-07 8.88653855726949e-08 1.23281438816645e-07 3.74059740200056e-08 3.63466577344003e-08 1.20887062612203e-06 5.31728280982040e-07 2.22245937870703e-08 1.24471844746278e-07 5.11735373064063e-07 3.13008213548308e-07 5.70247343660301e-08 7.23194564373494e-07 1.79616235944090e-07 6.78737172874271e-08 1.87999018332358e-07 1.56051038058590e-07 2.31029093824182e-08 3.65957708093627e-08 5.13581582166058e-07 2.55008648105981e-08 1.44166238137747e-07 3.81609462756446e-07 2.16242665285891e-07 2.34087134829968e-07 2.55408939395098e-07 5.31844204547311e-08 1.37230800917903e-07 2.24923680386313e-07 7.91242025449375e-08 1.56574476334133e-07 1.34926252415438e-07 1.70013819330808e-08 1.48130847036606e-07 1.10651211565701e-07 1.58123074045499e-07 1.47865663105776e-07 1.14316450201195e-07 2.02955526741989e-08 1.49518466142608e-07 2.99469635848321e-08 4.06175629714119e-07 2.32871553385763e-07 1.70948094081342e-07 1.86984334344187e-07 1.54774299548728e-07 1.27005955203776e-07 7.29605614875902e-08 4.26639317987837e-08 5.91930531596668e-08 1.50666658228087e-08 4.86748534643297e-08 1.64538615062307e-08 1.32252962938291e-07 1.06729078335828e-07 1.39785078669013e-07 1.39779800669610e-07 9.26422941859900e-08 1.13233915195479e-07 8.32946711657419e-08 1.67451405167575e-07 3.65621117891888e-08 2.21661117907828e-07 3.65652178907218e-08 1.41441861581090e-06 3.30075312403152e-07 2.05346680636497e-08 2.16432978289422e-07 1.92694668921994e-07 1.99379501668891e-07 2.60904461669433e-07 2.16709099204294e-07 1.33136064843243e-07 1.52413473502972e-07 7.53889226907776e-07 3.22036453180506e-07 1.68931528429636e-07 1.04094510285934e-07 1.60098934336117e-07 1.02657996503878e-07 6.83661821001145e-08 1.61931255758191e-07 2.01320024686194e-07 1.07534006069169e-07 1.07910634894973e-07 9.46522813533042e-08 1.66743437525985e-07 1.78365196465516e-07 1.90349497426267e-07 1.99051143944893e-07 1.10969246755729e-07 1.11264782143939e-07 1.02006294022338e-07 1.24767050443006e-07 1.04932154146443e-07 1.03659587531759e-07 4.90478970104965e-08 9.01107885624077e-08 9.30802687007756e-08 2.06842405795697e-07 1.53448550376276e-07 9.79061221486547e-08 8.26140384317179e-08 1.50146254483116e-07 1.40136146748372e-07 1.56837338087257e-07 1.76198808159403e-07 1.99122966368083e-07 1.23858764266714e-07 1.06727895602262e-07 8.15204687804434e-08 1.88227798887152e-08 2.31668781894091e-08 7.67325491571661e-07 1.97158231154847e-07 1.04232262587474e-07 8.81089549804027e-09 1.09695696650620e-08 3.67828021042941e-07 2.42873900856430e-07 9.30400519863338e-08 1.22815336391232e-08 1.04498084973760e-07 4.13726864269242e-07 1.28584375991528e-08 1.20376581165868e-07 1.07046398186240e-07 5.96207309583810e-08 3.66763563633301e-08 1.21422552113772e-07 1.39822102904246e-07 1.58475758239753e-07 8.54716186106630e-08 9.47107273229749e-08 1.57282457487923e-07 2.22341833330773e-07 1.47297286955243e-07 2.19435143761748e-07 1.39688617089499e-07 7.24259126481027e-08 7.09641458863346e-08 1.19226547380480e-07 7.87372467318109e-08 9.72314598010880e-08 7.74647075656411e-09 9.47412998435404e-08 1.16751285273194e-07 1.13487779361823e-07 1.13827758524977e-07 2.72522446715463e-07 8.16170870703966e-08 8.72321297381038e-08 9.95784392252335e-08 2.65989252708394e-09 1.06630932742284e-07 9.36921419305549e-08 8.41656329617571e-08 1.30269792124746e-08 4.86904164038956e-06 1.01469686899418e-07 1.47172552045969e-07 1.11949067863535e-07 9.34802107168088e-08 6.41098286680338e-08 6.68095594366830e-09 4.65659962399765e-08 1.74321722504626e-07 1.53177157686198e-07 1.72679939394816e-07 9.26791009109865e-08 7.38280843033631e-09 1.21431764801520e-08 1.83474589517062e-08 5.49758746890643e-08 5.49686356365556e-08 5.41396143667257e-07 1.02078716839878e-08 1.46280082306786e-07 9.20039209747377e-08 1.07464173701763e-08 4.37249887631680e-08 1.20696543908951e-07 7.37023067237918e-08 1.54370995646110e-07 8.75880053587604e-08 1.38972473988507e-07 1.50011697718075e-07 1.13900910702895e-07 7.30960487245964e-08 1.06352204500379e-07 7.15892552073097e-09 1.26382007766409e-08 2.34492999966371e-07 9.25652500580458e-08 8.91104525001921e-08 1.04346566674604e-08 7.96833204055166e-08 3.41626685510968e-07 1.46859973263572e-07 6.99097620123092e-08 5.60565018753087e-08 9.18716519344181e-08 5.82078430390537e-09 8.51757309259611e-08 1.41028716092150e-07 7.10210717526897e-09 3.02205722277794e-08 2.76205242367368e-07 9.08403872147274e-08 8.55641175181640e-08 8.07674139440669e-08 5.64950026938399e-09 1.47871928050032e-07 1.37623718221666e-07 9.60980796219824e-08 9.05395061229061e-09 3.58713661087815e-07 3.78246981154481e-07 1.97627162656081e-08 4.78463482905684e-08 5.47976120635378e-07 5.98012738422856e-07 1.38288635243591e-07 3.97209746106909e-08 1.04405402152745e-07 1.64230983323839e-08 2.14721179480984e-08 4.85083210883807e-08 1.22646011220379e-06 8.39456826640735e-09 8.27662116573820e-08 3.58891263221149e-07 9.16048888640066e-08 1.21278839928491e-07 2.31054125718236e-07 1.00889365297461e-07 1.19358834432565e-07 2.43427211256917e-07 9.11020950715102e-08 1.38162844699562e-07 8.00915682468241e-08 4.98258405386454e-09 7.30080219716715e-08 1.52701681888474e-07 2.93328698184570e-07 1.35353313498113e-07 4.59682925254202e-08 9.08782411223864e-08 2.20927979357592e-08 9.05503229704100e-08 6.68343694641667e-08 7.33025736057753e-08 7.49958147508063e-08 6.22824091009223e-09 8.02682015058001e-06 3.67877032868707e-07 7.19496678750717e-08 3.17758490462365e-09 5.75563157661276e-09 3.24272951280416e-09 1.00381201383279e-07 1.88260239049035e-07 7.07194739983604e-08 4.68947848174950e-09 4.16252458503278e-09 7.94576959843098e-08 2.74009776209153e-07 1.42430916804990e-07 1.26235913248699e-07 1.39626029880374e-07 1.16782761195100e-07 1.00256563902946e-07 -2.95101260456139e-09 6.83432403678117e-08 1.27348806727558e-07 5.96766339731236e-08 1.03604721020808e-07 1.21085249476580e-07 6.80561072346092e-08 2.39948064835149e-09 1.00688731186191e-08 2.43035685127838e-08 4.13254891501583e-08 9.63544005596039e-09 2.53883818143423e-07 7.44890597640385e-07];
w0=0.002;
F=2*(pi^2)*(k^2).*z_diff.*Phi;
x0 = linspace(-0.02,0.02,Nx);y0=x0;[X0,Y0] = meshgrid(x0,y0);
Uin=exp(-(X0.^2+Y0.^2)/w0^2);
x = x + z_diff(1)*tan(beta);
screen1 = exp(1i*((Kx.*x) + (Ky.*y))).*delfx.*delfy.*sqrt(F(1)).*R ;
Uout = Uin.*exp(1i.*screen1);
c=[0.740664357812470 0.715162315217582 0.689780546528124 0.664556687838984 0.639501229779350 0.614618312979130 0.589909677254809 0.565375929219662 0.541017064806704 0.516832720551119 0.492822307973243 0.468985091286926 0.445320235117717 0.421826835235231 0.398503939126698 0.375350560217132 0.352365687964806 0.329548295192595 0.306897343515746 0.284411787427262 0.262090577416753 0.239932662380474 0.217936991503006 0.196102515739251 0.174428188990141 0.152912969040777 0.131555818312352 0.110355704466664 0.0893116008928944 0.0684224870996102 0.0476873490298864 0.0271051793136574 0.00667497746850089 0.0136042499421828 0.0337334891863653 0.0537137192700918 0.0735459118688980 0.0932310312800026 0.112770034392025 0.132163870669524 0.151413482150099 0.170519803452171 0.189483761791847 0.208306277007520 0.226988261591059 0.245530620724636 0.263934252322323 0.282200047075789 0.300328888503445 0.318321653002534 0.336179209903699 0.353902421527639 0.371492143243500 0.388949223528713 0.406274504030009 0.423468819625392 0.440532998486862 0.457467862143721 0.474274225546305 0.490952897130006 0.507504678879476 0.523930366392895 0.540230748946220 0.556406609557339 0.572458725050048 0.588387866117797 0.604194797387153 0.619880277480917 0.635445059080876 0.650889888990134 0.666215508194993 0.681422651926368 0.696512049720699 0.711484425480339 0.726340497533411 0.741080978693105 0.755706576316408 0.770217992362264 0.784615923449129 0.798901060911951 0.813074090858528 0.827135694225279 0.841086546832386 0.854927319438336 0.868658677793846 0.882281282695167 0.895795790036781 0.909202850863477 0.922503111421817 0.935697213210995 0.948785793033077 0.961769483042646 0.974648910795838 0.987424699298783 1.00009746705545 1.01266782811491 1.02513639211797 1.03750376434332 1.04977054575300 1.06193733303735 1.07400471865938 1.08597329089862 1.09784363389434 1.10961632768826 1.12129194826677 1.13287106760249 1.14435425369543 1.15574207061353 1.16703507853271 1.17823383377643 1.18933888885472 1.20035079250267 1.21127008971854 1.22209732180122 1.23283302638735 1.24347773748787 1.25403198552414 1.26449629736359 1.27487119635488 1.28515720236266 1.29535483180181 1.30546459767133 1.31548700958769 1.32542257381781 1.33527179331163 1.34503516773420 1.35471319349739 1.36430636379121 1.37381516861470 1.38324009480640 1.39258162607448 1.40184024302645 1.41101642319850 1.42011064108442 1.42912336816425 1.43805507293243 1.44690622092571 1.45567727475060 1.46436869411057 1.47298093583279 1.48151445389465 1.48996969944983 1.49834712085410 1.50664716369079 1.51487027079592 1.52301688228302 1.53108743556759 1.53908236539135 1.54700210384610 1.55484708039729 1.56261772190731 1.57031445265850 1.57793769437581 1.58548786624928 1.59296538495611 1.60037066468257 1.60770411714556 1.61496615161393 1.62215717492952 1.62927759152798 1.63632780345927 1.64330821040796 1.65021920971321 1.65706119638862 1.66383456314170 1.67053970039319 1.67717699629614 1.68374683675467 1.69024960544263 1.69668568382193 1.70305545116068 1.70935928455115 1.71559755892740 1.72177064708287 1.72787891968756 1.73392274530517 1.73990249040993 1.74581851940328 1.75167119463032 1.75746087639608 1.76318792298160 1.76885269065981 1.77445553371120 1.77999680443936 1.78547685318630 1.79089602834756 1.79625467638721 1.80155314185264 1.80679176738913 1.81197089375438 1.81709085983270 1.82215200264920 1.82715465738367 1.83209915738443 1.83698583418192 1.84181501750219 1.84658703528021 1.85130221367304 1.85596087707287 1.86056334811985 1.86510994771484 1.86960099503199 1.87403680753115 1.87841770097023 1.88274398941727 1.88701598526258 1.89123399923051 1.89539834039132 1.89950931617273 1.90356723237146 1.90757239316461 1.91152510112087 1.91542565721170 1.91927436082231 1.92307150976254 1.92681740027765 1.93051232705897 1.93415658325440 1.93775046047891 1.94129424882478 1.94478823687186 1.94823271169764 1.95162795888723 1.95497426254328 1.95827190529575 1.96152116831153 1.96472233130413 1.96787567254306 1.97098146886325 1.97403999567435 1.97705152696986 1.98001633533631 1.98293469196218 1.98580686664685 1.98863312780943 1.99141374249746 1.99414897639556 1.99683909383401 1.99948435779718 2.00208502993198 2.00464137055607 2.00715363866619 2.00962209194621 2.01204698677524 2.01442857823560 2.01676712012071 2.01906286494297 2.02131606394144 2.02352696708957 2.02569582310279 2.02782287944605 2.02990838234126 2.03195257677470 2.03395570650435 2.03591801406711 2.03783974078601 2.03972112677735 2.04156241095768 2.04336383105087 2.04512562359498 2.04684802394913 2.04853126630031 2.05017558367013 2.05178120792145 2.05334836976503 2.05487729876606 2.05636822335072 2.05782137081251 2.05923696731876 2.06061523791685 2.06195640654055 2.06326069601621 2.06452832806891 2.06575952332861 2.06695450133616 2.06811348054936 2.06923667834885 2.07032431104407 2.07137659387907 2.07239374103836 2.07337596565262 2.07432347980443 2.07523649453394 2.07611521984447 2.07695986470806 2.07777063707106 2.07854774385950 2.07929139098462 2.08000178334822 2.08067912484798 2.08132361838281 2.08193546585808 2.08251486819086 2.08306202531507 2.08357713618662 2.08406039878854 2.08451201013601 2.08493216628138 2.08532106231914 2.08567889239087 2.08600584969017 2.08630212646748 2.08656791403493 2.08680340277114 2.08700878212594 2.08718424062516 2.08732996587524 2.08744614456794 2.08753296248490 2.08759060450230 2.08761925459532 2.08761909584274 2.08759031043135 2.08753307966046 2.08744758394630 2.08733400282638 2.08719251496389 2.08702329815202 2.08682652931821 2.08660238452849 2.08635103899165 2.08607266706347 2.08576744225093 2.08543553721630 2.08507712378131 2.08469237293121 2.08428145481885 2.08384453876873 2.08338179328099 2.08289338603538 2.08237948389527 2.08184025291152 2.08127585832643 2.08068646457760 2.08007223530177 2.07943333333869 2.07876992073487 2.07808215874743 2.07737020784777 2.07663422772538 2.07587437729149 2.07509081468279 2.07428369726507 2.07345318163688 2.07259942363312 2.07172257832864 2.07082280004183 2.06990024233815 2.06895505803365 2.06798739919850 2.06699741716044 2.06598526250827 2.06495108509530 2.06389503404273 2.06281725774310 2.06171790386362 2.06059711934957 2.05945505042762 2.05829184260918 2.05710764069365 2.05590258877174 2.05467683022873 2.05343050774771 2.05216376331278 2.05087673821232 2.04956957304210 2.04824240770851 2.04689538143169 2.04552863274867 2.04414229951646 2.04273651891521 2.04131142745123 2.03986716096009 2.03840385460964 2.03692164290309 2.03542065968197 2.03390103812916 2.03236291077188 2.03080640948460 2.02923166549207 2.02763880937220 2.02602797105897 2.02439927984538 2.02275286438630 2.02108885270135 2.01940737217775 2.01770854957318 2.01599251101859 2.01425938202100 2.01250928746633 2.01074235162217 2.00895869814052 2.00715845006058 2.00534172981146 2.00350865921493 2.00165935948813 1.99979395124624 1.99791255450517 1.99601528868428 1.99410227260896 1.99217362451332 1.99022946204283 1.98826990225688 1.98629506163147 1.98430505606170 1.98230000086442 1.98028001078079 1.97824519997880 1.97619568205582 1.97413157004115 1.97205297639850 1.96996001302854 1.96785279127132 1.96573142190885 1.96359601516744 1.96144668072028 1.95928352768979 1.95710666465011 1.95491619962948 1.95271224011267 1.95049489304337 1.94826426482658 1.94602046133099 1.94376358789132 1.94149374931069 1.93921104986296 1.93691559329504 1.93460748282926 1.93228682116561 1.92995371048410 1.92760825244698 1.92525054820109 1.92288069838009 1.92049880310668 1.91810496199492 1.91569927415240 1.91328183818251 1.91085275218661 1.90841211376627 1.90596002002548 1.90349656757275 1.90102185252339 1.89853597050162 1.89603901664270 1.89353108559514 1.89101227152279 1.88848266810698 1.88594236854864 1.88339146557039 1.88083005141866 1.87825821786576 1.87567605621199 1.87308365728765 1.87048111145519 1.86786850861116 1.86524593818833 1.86261348915771 1.85997125003053 1.85731930886031 1.85465775324484 1.85198667032819 1.84930614680269 1.84661626891091 1.84391712244766 1.84120879276190 1.83849136475875 1.83576492290140 1.83302955121309 1.83028533327899 1.82753235224814 1.82477069083540 1.82200043132329 1.81922165556395 1.81643444498099 1.81363888057138 1.81083504290734 1.80802301213817 1.80520286799215 1.80237468977836 1.79953855638852 1.79669454629885 1.79384273757188 1.79098320785825 1.78811603439854 1.78524129402510 1.78235906316378 1.77946941783578 1.77657243365938 1.77366818585177 1.77075674923075 1.76783819821655 1.76491260683352 1.76198004871193 1.75904059708966 1.75609432481398 1.75314130434320 1.75018160774846 1.74721530671537 1.74424247254577 1.74126317615938 1.73827748809551 1.73528547851471 1.73228721720050 1.72928277356095 1.72627221663041 1.72325561507115 1.72023303717496 1.71720455086485 1.71417022369661 1.71113012286052 1.70808431518289 1.70503286712770 1.70197584479823 1.69891331393861 1.69584533993546 1.69277198781941 1.68969332226677 1.68660940760100 1.68352030779434 1.68042608646938 1.67732680690054 1.67422253201569 1.67111332439765 1.66799924628574 1.66488035957729 1.66175672582918 1.65862840625934 1.65549546174827 1.65235795284053 1.64921593974624 1.64606948234258 1.64291864017527 1.63976347246002 1.63660403808406 1.63344039560754 1.63027260326505 1.62710071896701 1.62392480030119 1.62074490453409 1.61756108861240 1.61437340916446 1.61118192250163 1.60798668461974 1.60478775120050 1.60158517761291 1.59837901891464 1.59516932985347 1.59195616486864 1.58873957809224 1.58551962335059 1.58229635416566 1.57906982375634 1.57584008503991 1.57260719063331 1.56937119285456 1.56613214372404 1.56289009496590 1.55964509800932 1.55639720398990 1.55314646375097 1.54989292784488 1.54663664653434 1.54337766979374 1.54011604731041 1.53685182848594 1.53358506243751 1.53031579799910 1.52704408372284 1.52376996788025 1.52049349846351 1.51721472318676 1.51393368948733 1.51065044452699 1.50736503519323 1.50407750810048 1.50078790959138 1.49749628573799 1.49420268234301 1.49090714494105 1.48760971879982 1.48431044892133 1.48100938004314 1.47770655663956 1.47440202292281 1.47109582284426 1.46778800009561 1.46447859811008 1.46116766006355 1.45785522887583 1.45454134721172 1.45122605748225 1.44790940184585 1.44459142220945 1.44127216022968 1.43795165731401 1.43462995462187 1.43130709306582 1.42798311331269 1.42465805578467 1.42133196066046 1.41800486787641 1.41467681712758 1.41134784786894 1.40801799931637 1.40468731044786 1.40135582000454 1.39802356649183 1.39469058818047 1.39135692310765 1.38802260907807 1.38468768366504 1.38135218421152 1.37801614783119 1.37467961140955 1.37134261160493 1.36800518484960 1.36466736735075 1.36132919509161 1.35799070383243 1.35465192911156 1.35131290624645 1.34797367033472 1.34463425625514 1.34129469866868 1.33795503201952 1.33461529053606 1.33127550823193 1.32793571890697 1.32459595614830 1.32125625333121 1.31791664362027 1.31457715997020 1.31123783512696 1.30789870162865 1.30455979180654 1.30122113778599 1.29788277148748 1.29454472462753 1.29120702871964 1.28786971507532 1.28453281480497 1.28119635881886 1.27786037782809 1.27452490234548 1.27118996268656 1.26785558897046 1.26452181112088 1.26118865886698 1.25785616174431 1.25452434909574 1.25119325007237 1.24786289363441 1.24453330855215 1.24120452340678 1.23787656659136 1.23454946631169 1.23122325058718 1.22789794725176 1.22457358395477 1.22125018816181 1.21792778715567 1.21460640803712 1.21128607772588 1.20796682296139 1.20464867030376 1.20133164613454 1.19801577665766 1.19470108790021 1.19138760571334 1.18807535577308 1.18476436358118 1.18145465446596 1.17814625358312 1.17483918591663 1.17153347627945 1.16822914931448 1.16492622949528 1.16162474112694 1.15832470834688 1.15502615512566 1.15172910526776 1.14843358241246 1.14513961003454 1.14184721144515 1.13855640979258 1.13526722806305 1.13197968908148 1.12869381551230 1.12540962986023 1.12212715447104 1.11884641153231 1.11556742307426 1.11229021097045 1.10901479693858 1.10574120254124 1.10246944918668 1.09919955812955 1.09593155047166 1.09266544716271 1.08940126900108 1.08613903663452 1.08287877056091 1.07962049112901 1.07636421853917 1.07310997284407 1.06985777394945 1.06660764161482 1.06335959545421 1.06011365493683 1.05686983938786 1.05362816798911 1.05038865977972 1.04715133365691 1.04391620837666 1.04068330255439 1.03745263466568 1.03422422304698 1.03099808589625 1.02777424127369 1.02455270710241 1.02133350116911 1.01811664112476 1.01490214448529 1.01169002863224 1.00848031081345 1.00527300814371 1.00206813760545 0.998865716049361 0.995665760195108 0.992468286631939 0.989273311819364 0.986080852087796 0.982890923639205 0.979703542547760 0.976518724760467 0.973336486097822 0.970156842254431 0.966979808799657 0.963805401178249 0.960633634710965 0.957464524595207 0.954298085905637 0.951134333594803 0.947973282493756 0.944814947312659 0.941659342641416 0.938506482950264 0.935356382590394 0.932209055794548 0.929064516677626 0.925922779237284 0.922783857354535 0.919647764794513 0.916514553007848 0.913626501586297 0.957181910437377 1.18507611517074];
Ri=z_diff./cos(beta);
screens = zeros(Nx,Nx,length(F)-1);
for i = 2:length(F)
x = x + z_diff(i)*tan(beta);
screens(:,:,i)= screens(:, :, i-1) + exp(1i*((Kx.*x)+(Ky.*y))).*delfx.*delfy.*sqrt(F(i)).*R;
Hi = exp(1i*Kz*Ri(i) – c(i).*Ri(i));
Ui = fftshift(fft2(Uout));
Ui = Hi.*Ui;
Ui = ifft2(ifftshift(Ui));
Uio = Ui.*exp(1i.*screens(:,:,i));
I = Uio.*conj(Uio);
Uout = Uio;
end
% to calculate SigmaI
A1=0;A2=0;
for i1=1:Nx
for i2=1:Nx
I1 = I(i1,i2)^2 ;
A1 = A1 + I1 ;
end
end
for j1=1:Nx
for j2=1:Nx
I2 = I(j1,j2) ;
A2 = A2 + I2;
end
end
SI = abs(((A1/Nx)/((A2/Nx)^2)) – 1);
%to calculate BER
syms u
PI = (1/(u*sqrt(2*pi*SI)))*exp(-((log(u) + SI )^2)/(2*SI)) ;
SNR0 = 1;
SNR = SNR0/sqrt(1+SI*SNR0) ;
fun = PI*erfc(real((SNR.*u)/(2*sqrt(2))));
ff = matlabFunction(fun,’Vars’,u);
BER = (0.5*integral(ff,0,Inf))I need to calculate a parameter called SigmaI and BER, where the equation is
Here I is a 512*512 matrix. But the value of SigmaI that I calculated is not same as reported values.I think there is some error in writing the code. Also I need to calculate SigmaI for each F points (F is 1*757 matrix), but what I get is the value of SigmaI at the last point of F only. i.e, I need to generated SigmaI as 1*757 matrix. I am confused how to include it in the for loop. Similary BER also needed as a 1*757 matrix. Can anyone help me to get the right answer. The code is as follows,
clc;close all;clear all;
lambda = 532;
k = 2*pi/lambda;
z=linspace(1,757,757);
z_diff = (diff(z)) ;
z_diff = [0 z_diff];
tilt_angle=10;
beta=(pi/180)*tilt_angle;
Lx = 0.1;
Ly = Lx;
Nx = 512;
Ny = Nx ;
dx = Lx/Nx;
dy = Ly/Ny;
x = (-Nx/2:Nx/2-1)*dx;
y = (-Ny/2:Ny/2-1)*dy;
[X,Y] = meshgrid(x,y);
r = sqrt(X.^2 + Y.^2);
kx = meshgrid(-Nx/2:Nx/2-1)/(Nx.*dx);
ky = meshgrid(-Ny/2:Ny/2-1)/(Ny.*dy);
kz = ones(Nx);
Kx=cos(beta).*kx + sin(beta).*kz;
Ky=ky;
Kz=-sin(beta).*kx + cos(beta).*kz;
K2 = Kx.^2 + Ky.^2 + Kz.^2;
delfx = 1/(Lx);
delfy = delfx;
R = randn(Nx,Ny) ;
R = R – mean(R(:,:));
R = R/std(R(:,:));
Phi = [2.50310494762771e-07 2.50946965543003e-07 4.74127533715154e-07 5.24210357233832e-06 2.42362427581638e-07 1.42653443399616e-07 5.16930235276850e-07 9.04590700562310e-07 2.29541191637123e-06 3.60105794008093e-07 9.17845719860523e-08 2.50390367004531e-07 1.09738615765455e-06 1.00311041468925e-06 6.50810613011221e-08 3.02640252523566e-07 5.31047019902531e-07 1.80313245178286e-06 3.04099822876624e-06 1.47008194185741e-07 4.08290582950848e-08 3.82118426499270e-06 5.29334397036188e-07 4.87810778598663e-06 1.18782521297988e-06 1.16666772914768e-06 1.69778706192608e-06 7.67426466736916e-06 5.27799451227444e-06 4.23216916272082e-07 2.66828750584071e-05 2.46205729358867e-06 2.80169965568206e-06 2.97378024567976e-07 2.21170607901861e-07 3.41285818450589e-07 3.85275104621375e-08 4.05141179263807e-07 1.17629321652161e-06 4.95233464403551e-06 1.80125151270180e-06 2.81483058944610e-07 1.24528365857859e-05 6.86781782456521e-06 2.95828059847895e-06 1.27035361174474e-06 6.34388599513081e-07 2.32012818083199e-06 2.81784487117724e-06 1.46096455213802e-06 1.60178082889894e-06 1.94791694377124e-07 6.35459501021705e-08 8.30940388112504e-08 2.53354933929590e-07 4.31247522543152e-06 9.63180625859285e-07 8.03726503455623e-07 2.98282116276067e-07 9.25402679823575e-08 1.61856374619784e-07 1.73242501417858e-07 2.31570160754109e-07 1.78600321810053e-07 1.25598618058698e-07 1.63418364388577e-06 1.02774042441542e-06 8.32018926678718e-08 2.53586554087675e-07 2.53508325030189e-07 4.07413642129177e-08 2.42096085408459e-07 5.91587468209778e-07 1.27761778023523e-07 1.65773731666773e-07 1.79565395840267e-07 3.78521468221561e-07 1.21471607158554e-07 3.25378687175317e-07 1.25569084575180e-07 5.49035746100893e-08 4.07733632799329e-08 4.79103771763424e-07 3.27135102365317e-07 2.10496092551324e-07 1.33641668807187e-06 1.68227872575447e-06 1.52265748820018e-06 2.53683706505161e-07 1.25630494723704e-07 1.12347756326375e-06 2.53692684133802e-07 2.10500428113819e-07 2.52934873659000e-07 6.77249701528946e-07 2.95386782896753e-07 3.16617852613830e-07 3.59879226900604e-07 2.81244834536819e-07 2.35438339516804e-07 3.40806542459708e-07 6.44683615098099e-08 5.05945401350734e-07 2.57387924440325e-07 7.82108421793457e-08 2.52513556939930e-07 7.41154472489689e-08 8.95664707278605e-08 3.44823854262242e-07 2.57498619329261e-07 2.07939465354519e-06 7.18570183290631e-07 3.25198024230522e-07 2.11933525065655e-07 8.30783371984955e-08 1.65710628194624e-07 5.48396993890243e-08 5.95342783012939e-08 2.28819020334242e-07 1.99067722101735e-07 2.40425372248607e-07 2.51916559208949e-07 2.98446361528618e-07 2.82958505602994e-07 2.10599141757522e-07 4.60997674322361e-08 2.59856693650578e-07 1.47642122461920e-07 3.93574284250877e-07 3.94729289526600e-08 6.37347851352551e-08 2.51536627057736e-07 2.28438571372065e-07 1.90144303446780e-07 4.73626330414131e-08 6.44142268235402e-08 1.72106272576708e-06 1.70721924857358e-06 2.94643811973548e-07 3.55943119776846e-08 9.36518317402136e-08 4.31201179335937e-08 1.56428758776995e-07 3.19975996745435e-07 3.34275554966361e-07 1.20064760586921e-06 4.30984033789707e-07 2.15616245567332e-07 3.03074660779611e-07 3.29934827134432e-07 -2.24864187842034e-08 2.33412514429474e-07 3.21092520408291e-07 3.38617740923693e-07 6.04579881670076e-07 1.91481555229955e-07 9.38472397526705e-08 6.13052684855612e-07 3.97260343618278e-06 2.45355935394897e-07 3.47585309986832e-07 3.38923893338132e-07 2.20926360286704e-07 5.25446559955282e-07 2.84158336921376e-07 4.04755442008443e-07 3.35541338245773e-07 3.76856346223440e-07 2.75568777774655e-07 2.09025928742013e-07 7.10170870233622e-08 2.95787195332815e-07 5.59078661720798e-07 2.51150081156080e-07 4.02707325242296e-08 8.24148001852386e-08 2.57363940284162e-07 3.55816103375846e-07 3.95777597622744e-07 3.27993323594138e-07 3.52690891300866e-07 3.52278318886910e-07 5.06712192595194e-08 1.23808524289852e-07 8.39347385990663e-07 2.02892942754780e-07 7.97641133582245e-08 3.64530615247902e-07 9.11185642215493e-07 2.44511041473120e-07 3.24963966176285e-07 1.11685979674259e-07 2.86261990645848e-07 3.75634147009314e-08 2.16925989302430e-07 3.84116828662608e-07 2.71791109589261e-07 1.06845659312697e-07 2.02225581949648e-07 3.02535099485185e-07 3.11957552477906e-08 9.15881915538412e-08 9.18891121954120e-07 3.70106500980225e-07 2.25779726927071e-07 2.86067288473873e-07 5.66382866246259e-07 4.26632108086086e-07 4.53045634671475e-07 1.17973378714372e-06 3.40969918417227e-07 2.48643473538260e-07 2.64505922988546e-07 2.38444406096982e-07 3.47101823144428e-07 3.37625374999722e-07 3.20790426924069e-07 5.02178252920690e-08 1.73576015527609e-07 8.57402376593969e-07 1.80131811857122e-07 2.76964595681315e-07 2.14838038341036e-07 2.21053263051776e-07 1.59406260405821e-07 4.59614264881235e-08 3.78789455759776e-07 2.58966590318316e-07 7.75696011578299e-08 3.39990416320565e-07 3.24572509489827e-07 3.52020828992088e-08 6.49912862168267e-08 2.22828739301052e-07 2.13473046057573e-07 1.70720547021041e-07 2.19582224668132e-07 2.05914598785446e-07 1.14899310738254e-06 1.03415047080757e-07 1.89177690522258e-06 2.24175047702725e-07 3.76150153666139e-07 9.18124634120261e-08 2.27678254839140e-07 8.61346207114181e-08 3.38947999645138e-06 1.71880093129416e-07 2.22461873169689e-07 3.72427593494344e-08 6.76102058093114e-08 1.13163515787091e-06 7.04052219453715e-07 3.28310827940334e-07 2.12060821359437e-07 2.68576701610855e-07 2.04744061114503e-07 1.14622616867334e-07 4.35675529886048e-08 5.29665131717990e-08 3.50574437154752e-08 5.32920831968263e-08 1.04801149974382e-07 2.08316009852988e-07 2.77349913208742e-07 1.48756450473382e-07 3.78517042358300e-07 1.19222278136494e-07 4.57902170141890e-08 2.03249187200450e-07 9.32437812713631e-08 6.61503340988668e-07 1.01572927594225e-06 3.26294032932256e-07 2.26313604682662e-07 7.01012285236915e-08 7.61666326540900e-08 4.16954886967803e-08 4.41719683698357e-08 4.02549730011751e-08 4.41603434482274e-08 3.50371730851861e-08 3.00718061774876e-07 3.50372423542925e-08 5.32741630316562e-08 2.09046711312522e-07 3.75611845531339e-06 2.26535469768828e-07 4.62710159517236e-07 5.55357457448765e-07 4.16702305525217e-07 2.05922476618442e-07 2.06490274401431e-07 2.33754328058605e-07 1.66615319203810e-07 2.13390792614979e-07 2.54792444311713e-07 4.20241426628409e-07 6.95047952441784e-07 6.02254152247896e-07 1.56218004764843e-07 1.99836446669293e-07 1.62974708502310e-07 2.93420921132526e-07 1.67909832369442e-07 1.53692619622575e-07 8.89709805825161e-08 1.64148574413349e-07 1.82871518257336e-07 1.99566615308843e-07 1.59784291140960e-07 1.87893662090374e-07 2.77364481028229e-07 1.10443572547260e-07 2.18556580353372e-07 1.83932131011210e-07 7.94652011731045e-08 2.43919458395486e-07 1.59781205439559e-07 1.94642054497664e-07 1.29989372686070e-07 1.90910393259075e-07 2.84452061601644e-07 3.30006526167654e-07 1.93485493531741e-07 2.40209860863182e-07 4.15333943239071e-07 2.91343651778087e-07 2.58377576473351e-07 1.81274762632482e-07 1.88893039486970e-07 2.19428417763272e-07 2.20994023873646e-07 2.27950728874121e-07 1.64400439994395e-07 1.00341668297253e-07 1.67577483763212e-07 5.61980802260245e-08 3.04539633123467e-08 3.19018898206730e-08 3.89504322796163e-08 3.19941498021468e-07 5.41874921040340e-06 1.01776790218898e-06 1.29079721421378e-06 5.77887058141474e-07 2.79939362285509e-07 5.55989804582382e-08 2.11144624551603e-07 5.73140726411827e-08 5.35992572193921e-08 2.80066251579433e-07 1.76964657359828e-07 3.25199602895421e-07 2.18271466195228e-07 1.80628024038326e-07 4.69550563668357e-08 1.48055689005769e-07 1.82317859358405e-07 1.33063533148151e-07 2.62672490298873e-08 2.52416541944235e-08 2.08244390466210e-07 3.06261128674104e-07 2.18183988930487e-07 1.32114003617060e-07 3.13731744862144e-07 2.78980205382911e-07 2.42110700965470e-08 1.28818767334643e-07 3.48416502648141e-07 1.43250842379859e-07 2.58790299254369e-08 2.36803673262810e-08 2.54679999490770e-08 1.53423624973069e-07 2.11044574009824e-07 2.45219073821534e-08 5.40329423903049e-08 4.07828910547019e-08 2.86866659397290e-08 5.74108869690081e-08 3.17780519921456e-08 2.89072270765441e-07 6.46668413187508e-08 3.89801393203052e-07 1.62322978572959e-07 2.69026419637955e-07 4.76120100475985e-07 5.32185045407108e-07 1.57575408820348e-07 2.08858600548085e-07 1.87565977660685e-07 2.01108310997773e-07 3.95620143987532e-08 5.24866345380986e-08 8.64930520826212e-08 9.74072997804584e-07 2.54439638933078e-08 1.00154777975012e-07 9.42429455464106e-07 2.23088555779751e-07 2.02097796370716e-07 1.99163165408265e-07 9.26536634692885e-08 1.31298738607173e-07 1.97726692783641e-07 2.28150683478771e-07 2.17170907865184e-07 2.69677497220439e-08 1.54765400027711e-07 6.26255760215395e-08 1.46771827369792e-07 1.81515822529873e-07 1.72918459779846e-07 8.15990146285526e-08 9.85514009220808e-08 7.03396855430348e-07 5.93657045438661e-07 1.51834395684521e-07 9.76927764035926e-08 1.18527867299870e-07 2.71435324116586e-08 5.68571003566081e-08 1.65983256102705e-07 2.29129793972797e-07 5.88646431511064e-08 3.08684402204026e-05 2.38265317337181e-06 4.30752744717656e-07 1.04689461805175e-07 2.32270648752108e-07 6.07211466407868e-07 1.95341105985221e-08 7.38231690963101e-08 1.95129857199575e-07 4.01671898332107e-08 4.75072551754564e-08 2.49046064060719e-06 1.78142428447807e-07 2.60935684174315e-07 4.29594269700864e-08 1.14070714922750e-07 5.26390027271695e-08 6.74132420131039e-08 2.11045265009953e-07 7.27021148761358e-07 2.83886081059763e-07 2.76343292567963e-08 1.61294742863238e-07 1.83304573271511e-07 2.45251911632262e-07 9.18095053702886e-07 9.40457085677553e-07 2.90451584499496e-07 1.04003175628026e-07 1.08284695915254e-07 5.44402482199441e-08 2.02578013696944e-08 5.88615942025308e-08 1.04406254724335e-07 1.20598226687063e-07 5.71264670628078e-07 3.15144191075623e-07 2.23052176438872e-08 2.98936409995515e-08 2.92428609360162e-07 2.47505388371339e-07 2.72866577624107e-07 2.69881858030521e-07 1.85519336468060e-07 2.56402576998181e-07 8.88653855726949e-08 1.23281438816645e-07 3.74059740200056e-08 3.63466577344003e-08 1.20887062612203e-06 5.31728280982040e-07 2.22245937870703e-08 1.24471844746278e-07 5.11735373064063e-07 3.13008213548308e-07 5.70247343660301e-08 7.23194564373494e-07 1.79616235944090e-07 6.78737172874271e-08 1.87999018332358e-07 1.56051038058590e-07 2.31029093824182e-08 3.65957708093627e-08 5.13581582166058e-07 2.55008648105981e-08 1.44166238137747e-07 3.81609462756446e-07 2.16242665285891e-07 2.34087134829968e-07 2.55408939395098e-07 5.31844204547311e-08 1.37230800917903e-07 2.24923680386313e-07 7.91242025449375e-08 1.56574476334133e-07 1.34926252415438e-07 1.70013819330808e-08 1.48130847036606e-07 1.10651211565701e-07 1.58123074045499e-07 1.47865663105776e-07 1.14316450201195e-07 2.02955526741989e-08 1.49518466142608e-07 2.99469635848321e-08 4.06175629714119e-07 2.32871553385763e-07 1.70948094081342e-07 1.86984334344187e-07 1.54774299548728e-07 1.27005955203776e-07 7.29605614875902e-08 4.26639317987837e-08 5.91930531596668e-08 1.50666658228087e-08 4.86748534643297e-08 1.64538615062307e-08 1.32252962938291e-07 1.06729078335828e-07 1.39785078669013e-07 1.39779800669610e-07 9.26422941859900e-08 1.13233915195479e-07 8.32946711657419e-08 1.67451405167575e-07 3.65621117891888e-08 2.21661117907828e-07 3.65652178907218e-08 1.41441861581090e-06 3.30075312403152e-07 2.05346680636497e-08 2.16432978289422e-07 1.92694668921994e-07 1.99379501668891e-07 2.60904461669433e-07 2.16709099204294e-07 1.33136064843243e-07 1.52413473502972e-07 7.53889226907776e-07 3.22036453180506e-07 1.68931528429636e-07 1.04094510285934e-07 1.60098934336117e-07 1.02657996503878e-07 6.83661821001145e-08 1.61931255758191e-07 2.01320024686194e-07 1.07534006069169e-07 1.07910634894973e-07 9.46522813533042e-08 1.66743437525985e-07 1.78365196465516e-07 1.90349497426267e-07 1.99051143944893e-07 1.10969246755729e-07 1.11264782143939e-07 1.02006294022338e-07 1.24767050443006e-07 1.04932154146443e-07 1.03659587531759e-07 4.90478970104965e-08 9.01107885624077e-08 9.30802687007756e-08 2.06842405795697e-07 1.53448550376276e-07 9.79061221486547e-08 8.26140384317179e-08 1.50146254483116e-07 1.40136146748372e-07 1.56837338087257e-07 1.76198808159403e-07 1.99122966368083e-07 1.23858764266714e-07 1.06727895602262e-07 8.15204687804434e-08 1.88227798887152e-08 2.31668781894091e-08 7.67325491571661e-07 1.97158231154847e-07 1.04232262587474e-07 8.81089549804027e-09 1.09695696650620e-08 3.67828021042941e-07 2.42873900856430e-07 9.30400519863338e-08 1.22815336391232e-08 1.04498084973760e-07 4.13726864269242e-07 1.28584375991528e-08 1.20376581165868e-07 1.07046398186240e-07 5.96207309583810e-08 3.66763563633301e-08 1.21422552113772e-07 1.39822102904246e-07 1.58475758239753e-07 8.54716186106630e-08 9.47107273229749e-08 1.57282457487923e-07 2.22341833330773e-07 1.47297286955243e-07 2.19435143761748e-07 1.39688617089499e-07 7.24259126481027e-08 7.09641458863346e-08 1.19226547380480e-07 7.87372467318109e-08 9.72314598010880e-08 7.74647075656411e-09 9.47412998435404e-08 1.16751285273194e-07 1.13487779361823e-07 1.13827758524977e-07 2.72522446715463e-07 8.16170870703966e-08 8.72321297381038e-08 9.95784392252335e-08 2.65989252708394e-09 1.06630932742284e-07 9.36921419305549e-08 8.41656329617571e-08 1.30269792124746e-08 4.86904164038956e-06 1.01469686899418e-07 1.47172552045969e-07 1.11949067863535e-07 9.34802107168088e-08 6.41098286680338e-08 6.68095594366830e-09 4.65659962399765e-08 1.74321722504626e-07 1.53177157686198e-07 1.72679939394816e-07 9.26791009109865e-08 7.38280843033631e-09 1.21431764801520e-08 1.83474589517062e-08 5.49758746890643e-08 5.49686356365556e-08 5.41396143667257e-07 1.02078716839878e-08 1.46280082306786e-07 9.20039209747377e-08 1.07464173701763e-08 4.37249887631680e-08 1.20696543908951e-07 7.37023067237918e-08 1.54370995646110e-07 8.75880053587604e-08 1.38972473988507e-07 1.50011697718075e-07 1.13900910702895e-07 7.30960487245964e-08 1.06352204500379e-07 7.15892552073097e-09 1.26382007766409e-08 2.34492999966371e-07 9.25652500580458e-08 8.91104525001921e-08 1.04346566674604e-08 7.96833204055166e-08 3.41626685510968e-07 1.46859973263572e-07 6.99097620123092e-08 5.60565018753087e-08 9.18716519344181e-08 5.82078430390537e-09 8.51757309259611e-08 1.41028716092150e-07 7.10210717526897e-09 3.02205722277794e-08 2.76205242367368e-07 9.08403872147274e-08 8.55641175181640e-08 8.07674139440669e-08 5.64950026938399e-09 1.47871928050032e-07 1.37623718221666e-07 9.60980796219824e-08 9.05395061229061e-09 3.58713661087815e-07 3.78246981154481e-07 1.97627162656081e-08 4.78463482905684e-08 5.47976120635378e-07 5.98012738422856e-07 1.38288635243591e-07 3.97209746106909e-08 1.04405402152745e-07 1.64230983323839e-08 2.14721179480984e-08 4.85083210883807e-08 1.22646011220379e-06 8.39456826640735e-09 8.27662116573820e-08 3.58891263221149e-07 9.16048888640066e-08 1.21278839928491e-07 2.31054125718236e-07 1.00889365297461e-07 1.19358834432565e-07 2.43427211256917e-07 9.11020950715102e-08 1.38162844699562e-07 8.00915682468241e-08 4.98258405386454e-09 7.30080219716715e-08 1.52701681888474e-07 2.93328698184570e-07 1.35353313498113e-07 4.59682925254202e-08 9.08782411223864e-08 2.20927979357592e-08 9.05503229704100e-08 6.68343694641667e-08 7.33025736057753e-08 7.49958147508063e-08 6.22824091009223e-09 8.02682015058001e-06 3.67877032868707e-07 7.19496678750717e-08 3.17758490462365e-09 5.75563157661276e-09 3.24272951280416e-09 1.00381201383279e-07 1.88260239049035e-07 7.07194739983604e-08 4.68947848174950e-09 4.16252458503278e-09 7.94576959843098e-08 2.74009776209153e-07 1.42430916804990e-07 1.26235913248699e-07 1.39626029880374e-07 1.16782761195100e-07 1.00256563902946e-07 -2.95101260456139e-09 6.83432403678117e-08 1.27348806727558e-07 5.96766339731236e-08 1.03604721020808e-07 1.21085249476580e-07 6.80561072346092e-08 2.39948064835149e-09 1.00688731186191e-08 2.43035685127838e-08 4.13254891501583e-08 9.63544005596039e-09 2.53883818143423e-07 7.44890597640385e-07];
w0=0.002;
F=2*(pi^2)*(k^2).*z_diff.*Phi;
x0 = linspace(-0.02,0.02,Nx);y0=x0;[X0,Y0] = meshgrid(x0,y0);
Uin=exp(-(X0.^2+Y0.^2)/w0^2);
x = x + z_diff(1)*tan(beta);
screen1 = exp(1i*((Kx.*x) + (Ky.*y))).*delfx.*delfy.*sqrt(F(1)).*R ;
Uout = Uin.*exp(1i.*screen1);
c=[0.740664357812470 0.715162315217582 0.689780546528124 0.664556687838984 0.639501229779350 0.614618312979130 0.589909677254809 0.565375929219662 0.541017064806704 0.516832720551119 0.492822307973243 0.468985091286926 0.445320235117717 0.421826835235231 0.398503939126698 0.375350560217132 0.352365687964806 0.329548295192595 0.306897343515746 0.284411787427262 0.262090577416753 0.239932662380474 0.217936991503006 0.196102515739251 0.174428188990141 0.152912969040777 0.131555818312352 0.110355704466664 0.0893116008928944 0.0684224870996102 0.0476873490298864 0.0271051793136574 0.00667497746850089 0.0136042499421828 0.0337334891863653 0.0537137192700918 0.0735459118688980 0.0932310312800026 0.112770034392025 0.132163870669524 0.151413482150099 0.170519803452171 0.189483761791847 0.208306277007520 0.226988261591059 0.245530620724636 0.263934252322323 0.282200047075789 0.300328888503445 0.318321653002534 0.336179209903699 0.353902421527639 0.371492143243500 0.388949223528713 0.406274504030009 0.423468819625392 0.440532998486862 0.457467862143721 0.474274225546305 0.490952897130006 0.507504678879476 0.523930366392895 0.540230748946220 0.556406609557339 0.572458725050048 0.588387866117797 0.604194797387153 0.619880277480917 0.635445059080876 0.650889888990134 0.666215508194993 0.681422651926368 0.696512049720699 0.711484425480339 0.726340497533411 0.741080978693105 0.755706576316408 0.770217992362264 0.784615923449129 0.798901060911951 0.813074090858528 0.827135694225279 0.841086546832386 0.854927319438336 0.868658677793846 0.882281282695167 0.895795790036781 0.909202850863477 0.922503111421817 0.935697213210995 0.948785793033077 0.961769483042646 0.974648910795838 0.987424699298783 1.00009746705545 1.01266782811491 1.02513639211797 1.03750376434332 1.04977054575300 1.06193733303735 1.07400471865938 1.08597329089862 1.09784363389434 1.10961632768826 1.12129194826677 1.13287106760249 1.14435425369543 1.15574207061353 1.16703507853271 1.17823383377643 1.18933888885472 1.20035079250267 1.21127008971854 1.22209732180122 1.23283302638735 1.24347773748787 1.25403198552414 1.26449629736359 1.27487119635488 1.28515720236266 1.29535483180181 1.30546459767133 1.31548700958769 1.32542257381781 1.33527179331163 1.34503516773420 1.35471319349739 1.36430636379121 1.37381516861470 1.38324009480640 1.39258162607448 1.40184024302645 1.41101642319850 1.42011064108442 1.42912336816425 1.43805507293243 1.44690622092571 1.45567727475060 1.46436869411057 1.47298093583279 1.48151445389465 1.48996969944983 1.49834712085410 1.50664716369079 1.51487027079592 1.52301688228302 1.53108743556759 1.53908236539135 1.54700210384610 1.55484708039729 1.56261772190731 1.57031445265850 1.57793769437581 1.58548786624928 1.59296538495611 1.60037066468257 1.60770411714556 1.61496615161393 1.62215717492952 1.62927759152798 1.63632780345927 1.64330821040796 1.65021920971321 1.65706119638862 1.66383456314170 1.67053970039319 1.67717699629614 1.68374683675467 1.69024960544263 1.69668568382193 1.70305545116068 1.70935928455115 1.71559755892740 1.72177064708287 1.72787891968756 1.73392274530517 1.73990249040993 1.74581851940328 1.75167119463032 1.75746087639608 1.76318792298160 1.76885269065981 1.77445553371120 1.77999680443936 1.78547685318630 1.79089602834756 1.79625467638721 1.80155314185264 1.80679176738913 1.81197089375438 1.81709085983270 1.82215200264920 1.82715465738367 1.83209915738443 1.83698583418192 1.84181501750219 1.84658703528021 1.85130221367304 1.85596087707287 1.86056334811985 1.86510994771484 1.86960099503199 1.87403680753115 1.87841770097023 1.88274398941727 1.88701598526258 1.89123399923051 1.89539834039132 1.89950931617273 1.90356723237146 1.90757239316461 1.91152510112087 1.91542565721170 1.91927436082231 1.92307150976254 1.92681740027765 1.93051232705897 1.93415658325440 1.93775046047891 1.94129424882478 1.94478823687186 1.94823271169764 1.95162795888723 1.95497426254328 1.95827190529575 1.96152116831153 1.96472233130413 1.96787567254306 1.97098146886325 1.97403999567435 1.97705152696986 1.98001633533631 1.98293469196218 1.98580686664685 1.98863312780943 1.99141374249746 1.99414897639556 1.99683909383401 1.99948435779718 2.00208502993198 2.00464137055607 2.00715363866619 2.00962209194621 2.01204698677524 2.01442857823560 2.01676712012071 2.01906286494297 2.02131606394144 2.02352696708957 2.02569582310279 2.02782287944605 2.02990838234126 2.03195257677470 2.03395570650435 2.03591801406711 2.03783974078601 2.03972112677735 2.04156241095768 2.04336383105087 2.04512562359498 2.04684802394913 2.04853126630031 2.05017558367013 2.05178120792145 2.05334836976503 2.05487729876606 2.05636822335072 2.05782137081251 2.05923696731876 2.06061523791685 2.06195640654055 2.06326069601621 2.06452832806891 2.06575952332861 2.06695450133616 2.06811348054936 2.06923667834885 2.07032431104407 2.07137659387907 2.07239374103836 2.07337596565262 2.07432347980443 2.07523649453394 2.07611521984447 2.07695986470806 2.07777063707106 2.07854774385950 2.07929139098462 2.08000178334822 2.08067912484798 2.08132361838281 2.08193546585808 2.08251486819086 2.08306202531507 2.08357713618662 2.08406039878854 2.08451201013601 2.08493216628138 2.08532106231914 2.08567889239087 2.08600584969017 2.08630212646748 2.08656791403493 2.08680340277114 2.08700878212594 2.08718424062516 2.08732996587524 2.08744614456794 2.08753296248490 2.08759060450230 2.08761925459532 2.08761909584274 2.08759031043135 2.08753307966046 2.08744758394630 2.08733400282638 2.08719251496389 2.08702329815202 2.08682652931821 2.08660238452849 2.08635103899165 2.08607266706347 2.08576744225093 2.08543553721630 2.08507712378131 2.08469237293121 2.08428145481885 2.08384453876873 2.08338179328099 2.08289338603538 2.08237948389527 2.08184025291152 2.08127585832643 2.08068646457760 2.08007223530177 2.07943333333869 2.07876992073487 2.07808215874743 2.07737020784777 2.07663422772538 2.07587437729149 2.07509081468279 2.07428369726507 2.07345318163688 2.07259942363312 2.07172257832864 2.07082280004183 2.06990024233815 2.06895505803365 2.06798739919850 2.06699741716044 2.06598526250827 2.06495108509530 2.06389503404273 2.06281725774310 2.06171790386362 2.06059711934957 2.05945505042762 2.05829184260918 2.05710764069365 2.05590258877174 2.05467683022873 2.05343050774771 2.05216376331278 2.05087673821232 2.04956957304210 2.04824240770851 2.04689538143169 2.04552863274867 2.04414229951646 2.04273651891521 2.04131142745123 2.03986716096009 2.03840385460964 2.03692164290309 2.03542065968197 2.03390103812916 2.03236291077188 2.03080640948460 2.02923166549207 2.02763880937220 2.02602797105897 2.02439927984538 2.02275286438630 2.02108885270135 2.01940737217775 2.01770854957318 2.01599251101859 2.01425938202100 2.01250928746633 2.01074235162217 2.00895869814052 2.00715845006058 2.00534172981146 2.00350865921493 2.00165935948813 1.99979395124624 1.99791255450517 1.99601528868428 1.99410227260896 1.99217362451332 1.99022946204283 1.98826990225688 1.98629506163147 1.98430505606170 1.98230000086442 1.98028001078079 1.97824519997880 1.97619568205582 1.97413157004115 1.97205297639850 1.96996001302854 1.96785279127132 1.96573142190885 1.96359601516744 1.96144668072028 1.95928352768979 1.95710666465011 1.95491619962948 1.95271224011267 1.95049489304337 1.94826426482658 1.94602046133099 1.94376358789132 1.94149374931069 1.93921104986296 1.93691559329504 1.93460748282926 1.93228682116561 1.92995371048410 1.92760825244698 1.92525054820109 1.92288069838009 1.92049880310668 1.91810496199492 1.91569927415240 1.91328183818251 1.91085275218661 1.90841211376627 1.90596002002548 1.90349656757275 1.90102185252339 1.89853597050162 1.89603901664270 1.89353108559514 1.89101227152279 1.88848266810698 1.88594236854864 1.88339146557039 1.88083005141866 1.87825821786576 1.87567605621199 1.87308365728765 1.87048111145519 1.86786850861116 1.86524593818833 1.86261348915771 1.85997125003053 1.85731930886031 1.85465775324484 1.85198667032819 1.84930614680269 1.84661626891091 1.84391712244766 1.84120879276190 1.83849136475875 1.83576492290140 1.83302955121309 1.83028533327899 1.82753235224814 1.82477069083540 1.82200043132329 1.81922165556395 1.81643444498099 1.81363888057138 1.81083504290734 1.80802301213817 1.80520286799215 1.80237468977836 1.79953855638852 1.79669454629885 1.79384273757188 1.79098320785825 1.78811603439854 1.78524129402510 1.78235906316378 1.77946941783578 1.77657243365938 1.77366818585177 1.77075674923075 1.76783819821655 1.76491260683352 1.76198004871193 1.75904059708966 1.75609432481398 1.75314130434320 1.75018160774846 1.74721530671537 1.74424247254577 1.74126317615938 1.73827748809551 1.73528547851471 1.73228721720050 1.72928277356095 1.72627221663041 1.72325561507115 1.72023303717496 1.71720455086485 1.71417022369661 1.71113012286052 1.70808431518289 1.70503286712770 1.70197584479823 1.69891331393861 1.69584533993546 1.69277198781941 1.68969332226677 1.68660940760100 1.68352030779434 1.68042608646938 1.67732680690054 1.67422253201569 1.67111332439765 1.66799924628574 1.66488035957729 1.66175672582918 1.65862840625934 1.65549546174827 1.65235795284053 1.64921593974624 1.64606948234258 1.64291864017527 1.63976347246002 1.63660403808406 1.63344039560754 1.63027260326505 1.62710071896701 1.62392480030119 1.62074490453409 1.61756108861240 1.61437340916446 1.61118192250163 1.60798668461974 1.60478775120050 1.60158517761291 1.59837901891464 1.59516932985347 1.59195616486864 1.58873957809224 1.58551962335059 1.58229635416566 1.57906982375634 1.57584008503991 1.57260719063331 1.56937119285456 1.56613214372404 1.56289009496590 1.55964509800932 1.55639720398990 1.55314646375097 1.54989292784488 1.54663664653434 1.54337766979374 1.54011604731041 1.53685182848594 1.53358506243751 1.53031579799910 1.52704408372284 1.52376996788025 1.52049349846351 1.51721472318676 1.51393368948733 1.51065044452699 1.50736503519323 1.50407750810048 1.50078790959138 1.49749628573799 1.49420268234301 1.49090714494105 1.48760971879982 1.48431044892133 1.48100938004314 1.47770655663956 1.47440202292281 1.47109582284426 1.46778800009561 1.46447859811008 1.46116766006355 1.45785522887583 1.45454134721172 1.45122605748225 1.44790940184585 1.44459142220945 1.44127216022968 1.43795165731401 1.43462995462187 1.43130709306582 1.42798311331269 1.42465805578467 1.42133196066046 1.41800486787641 1.41467681712758 1.41134784786894 1.40801799931637 1.40468731044786 1.40135582000454 1.39802356649183 1.39469058818047 1.39135692310765 1.38802260907807 1.38468768366504 1.38135218421152 1.37801614783119 1.37467961140955 1.37134261160493 1.36800518484960 1.36466736735075 1.36132919509161 1.35799070383243 1.35465192911156 1.35131290624645 1.34797367033472 1.34463425625514 1.34129469866868 1.33795503201952 1.33461529053606 1.33127550823193 1.32793571890697 1.32459595614830 1.32125625333121 1.31791664362027 1.31457715997020 1.31123783512696 1.30789870162865 1.30455979180654 1.30122113778599 1.29788277148748 1.29454472462753 1.29120702871964 1.28786971507532 1.28453281480497 1.28119635881886 1.27786037782809 1.27452490234548 1.27118996268656 1.26785558897046 1.26452181112088 1.26118865886698 1.25785616174431 1.25452434909574 1.25119325007237 1.24786289363441 1.24453330855215 1.24120452340678 1.23787656659136 1.23454946631169 1.23122325058718 1.22789794725176 1.22457358395477 1.22125018816181 1.21792778715567 1.21460640803712 1.21128607772588 1.20796682296139 1.20464867030376 1.20133164613454 1.19801577665766 1.19470108790021 1.19138760571334 1.18807535577308 1.18476436358118 1.18145465446596 1.17814625358312 1.17483918591663 1.17153347627945 1.16822914931448 1.16492622949528 1.16162474112694 1.15832470834688 1.15502615512566 1.15172910526776 1.14843358241246 1.14513961003454 1.14184721144515 1.13855640979258 1.13526722806305 1.13197968908148 1.12869381551230 1.12540962986023 1.12212715447104 1.11884641153231 1.11556742307426 1.11229021097045 1.10901479693858 1.10574120254124 1.10246944918668 1.09919955812955 1.09593155047166 1.09266544716271 1.08940126900108 1.08613903663452 1.08287877056091 1.07962049112901 1.07636421853917 1.07310997284407 1.06985777394945 1.06660764161482 1.06335959545421 1.06011365493683 1.05686983938786 1.05362816798911 1.05038865977972 1.04715133365691 1.04391620837666 1.04068330255439 1.03745263466568 1.03422422304698 1.03099808589625 1.02777424127369 1.02455270710241 1.02133350116911 1.01811664112476 1.01490214448529 1.01169002863224 1.00848031081345 1.00527300814371 1.00206813760545 0.998865716049361 0.995665760195108 0.992468286631939 0.989273311819364 0.986080852087796 0.982890923639205 0.979703542547760 0.976518724760467 0.973336486097822 0.970156842254431 0.966979808799657 0.963805401178249 0.960633634710965 0.957464524595207 0.954298085905637 0.951134333594803 0.947973282493756 0.944814947312659 0.941659342641416 0.938506482950264 0.935356382590394 0.932209055794548 0.929064516677626 0.925922779237284 0.922783857354535 0.919647764794513 0.916514553007848 0.913626501586297 0.957181910437377 1.18507611517074];
Ri=z_diff./cos(beta);
screens = zeros(Nx,Nx,length(F)-1);
for i = 2:length(F)
x = x + z_diff(i)*tan(beta);
screens(:,:,i)= screens(:, :, i-1) + exp(1i*((Kx.*x)+(Ky.*y))).*delfx.*delfy.*sqrt(F(i)).*R;
Hi = exp(1i*Kz*Ri(i) – c(i).*Ri(i));
Ui = fftshift(fft2(Uout));
Ui = Hi.*Ui;
Ui = ifft2(ifftshift(Ui));
Uio = Ui.*exp(1i.*screens(:,:,i));
I = Uio.*conj(Uio);
Uout = Uio;
end
% to calculate SigmaI
A1=0;A2=0;
for i1=1:Nx
for i2=1:Nx
I1 = I(i1,i2)^2 ;
A1 = A1 + I1 ;
end
end
for j1=1:Nx
for j2=1:Nx
I2 = I(j1,j2) ;
A2 = A2 + I2;
end
end
SI = abs(((A1/Nx)/((A2/Nx)^2)) – 1);
%to calculate BER
syms u
PI = (1/(u*sqrt(2*pi*SI)))*exp(-((log(u) + SI )^2)/(2*SI)) ;
SNR0 = 1;
SNR = SNR0/sqrt(1+SI*SNR0) ;
fun = PI*erfc(real((SNR.*u)/(2*sqrt(2))));
ff = matlabFunction(fun,’Vars’,u);
BER = (0.5*integral(ff,0,Inf)) I need to calculate a parameter called SigmaI and BER, where the equation is
Here I is a 512*512 matrix. But the value of SigmaI that I calculated is not same as reported values.I think there is some error in writing the code. Also I need to calculate SigmaI for each F points (F is 1*757 matrix), but what I get is the value of SigmaI at the last point of F only. i.e, I need to generated SigmaI as 1*757 matrix. I am confused how to include it in the for loop. Similary BER also needed as a 1*757 matrix. Can anyone help me to get the right answer. The code is as follows,
clc;close all;clear all;
lambda = 532;
k = 2*pi/lambda;
z=linspace(1,757,757);
z_diff = (diff(z)) ;
z_diff = [0 z_diff];
tilt_angle=10;
beta=(pi/180)*tilt_angle;
Lx = 0.1;
Ly = Lx;
Nx = 512;
Ny = Nx ;
dx = Lx/Nx;
dy = Ly/Ny;
x = (-Nx/2:Nx/2-1)*dx;
y = (-Ny/2:Ny/2-1)*dy;
[X,Y] = meshgrid(x,y);
r = sqrt(X.^2 + Y.^2);
kx = meshgrid(-Nx/2:Nx/2-1)/(Nx.*dx);
ky = meshgrid(-Ny/2:Ny/2-1)/(Ny.*dy);
kz = ones(Nx);
Kx=cos(beta).*kx + sin(beta).*kz;
Ky=ky;
Kz=-sin(beta).*kx + cos(beta).*kz;
K2 = Kx.^2 + Ky.^2 + Kz.^2;
delfx = 1/(Lx);
delfy = delfx;
R = randn(Nx,Ny) ;
R = R – mean(R(:,:));
R = R/std(R(:,:));
Phi = [2.50310494762771e-07 2.50946965543003e-07 4.74127533715154e-07 5.24210357233832e-06 2.42362427581638e-07 1.42653443399616e-07 5.16930235276850e-07 9.04590700562310e-07 2.29541191637123e-06 3.60105794008093e-07 9.17845719860523e-08 2.50390367004531e-07 1.09738615765455e-06 1.00311041468925e-06 6.50810613011221e-08 3.02640252523566e-07 5.31047019902531e-07 1.80313245178286e-06 3.04099822876624e-06 1.47008194185741e-07 4.08290582950848e-08 3.82118426499270e-06 5.29334397036188e-07 4.87810778598663e-06 1.18782521297988e-06 1.16666772914768e-06 1.69778706192608e-06 7.67426466736916e-06 5.27799451227444e-06 4.23216916272082e-07 2.66828750584071e-05 2.46205729358867e-06 2.80169965568206e-06 2.97378024567976e-07 2.21170607901861e-07 3.41285818450589e-07 3.85275104621375e-08 4.05141179263807e-07 1.17629321652161e-06 4.95233464403551e-06 1.80125151270180e-06 2.81483058944610e-07 1.24528365857859e-05 6.86781782456521e-06 2.95828059847895e-06 1.27035361174474e-06 6.34388599513081e-07 2.32012818083199e-06 2.81784487117724e-06 1.46096455213802e-06 1.60178082889894e-06 1.94791694377124e-07 6.35459501021705e-08 8.30940388112504e-08 2.53354933929590e-07 4.31247522543152e-06 9.63180625859285e-07 8.03726503455623e-07 2.98282116276067e-07 9.25402679823575e-08 1.61856374619784e-07 1.73242501417858e-07 2.31570160754109e-07 1.78600321810053e-07 1.25598618058698e-07 1.63418364388577e-06 1.02774042441542e-06 8.32018926678718e-08 2.53586554087675e-07 2.53508325030189e-07 4.07413642129177e-08 2.42096085408459e-07 5.91587468209778e-07 1.27761778023523e-07 1.65773731666773e-07 1.79565395840267e-07 3.78521468221561e-07 1.21471607158554e-07 3.25378687175317e-07 1.25569084575180e-07 5.49035746100893e-08 4.07733632799329e-08 4.79103771763424e-07 3.27135102365317e-07 2.10496092551324e-07 1.33641668807187e-06 1.68227872575447e-06 1.52265748820018e-06 2.53683706505161e-07 1.25630494723704e-07 1.12347756326375e-06 2.53692684133802e-07 2.10500428113819e-07 2.52934873659000e-07 6.77249701528946e-07 2.95386782896753e-07 3.16617852613830e-07 3.59879226900604e-07 2.81244834536819e-07 2.35438339516804e-07 3.40806542459708e-07 6.44683615098099e-08 5.05945401350734e-07 2.57387924440325e-07 7.82108421793457e-08 2.52513556939930e-07 7.41154472489689e-08 8.95664707278605e-08 3.44823854262242e-07 2.57498619329261e-07 2.07939465354519e-06 7.18570183290631e-07 3.25198024230522e-07 2.11933525065655e-07 8.30783371984955e-08 1.65710628194624e-07 5.48396993890243e-08 5.95342783012939e-08 2.28819020334242e-07 1.99067722101735e-07 2.40425372248607e-07 2.51916559208949e-07 2.98446361528618e-07 2.82958505602994e-07 2.10599141757522e-07 4.60997674322361e-08 2.59856693650578e-07 1.47642122461920e-07 3.93574284250877e-07 3.94729289526600e-08 6.37347851352551e-08 2.51536627057736e-07 2.28438571372065e-07 1.90144303446780e-07 4.73626330414131e-08 6.44142268235402e-08 1.72106272576708e-06 1.70721924857358e-06 2.94643811973548e-07 3.55943119776846e-08 9.36518317402136e-08 4.31201179335937e-08 1.56428758776995e-07 3.19975996745435e-07 3.34275554966361e-07 1.20064760586921e-06 4.30984033789707e-07 2.15616245567332e-07 3.03074660779611e-07 3.29934827134432e-07 -2.24864187842034e-08 2.33412514429474e-07 3.21092520408291e-07 3.38617740923693e-07 6.04579881670076e-07 1.91481555229955e-07 9.38472397526705e-08 6.13052684855612e-07 3.97260343618278e-06 2.45355935394897e-07 3.47585309986832e-07 3.38923893338132e-07 2.20926360286704e-07 5.25446559955282e-07 2.84158336921376e-07 4.04755442008443e-07 3.35541338245773e-07 3.76856346223440e-07 2.75568777774655e-07 2.09025928742013e-07 7.10170870233622e-08 2.95787195332815e-07 5.59078661720798e-07 2.51150081156080e-07 4.02707325242296e-08 8.24148001852386e-08 2.57363940284162e-07 3.55816103375846e-07 3.95777597622744e-07 3.27993323594138e-07 3.52690891300866e-07 3.52278318886910e-07 5.06712192595194e-08 1.23808524289852e-07 8.39347385990663e-07 2.02892942754780e-07 7.97641133582245e-08 3.64530615247902e-07 9.11185642215493e-07 2.44511041473120e-07 3.24963966176285e-07 1.11685979674259e-07 2.86261990645848e-07 3.75634147009314e-08 2.16925989302430e-07 3.84116828662608e-07 2.71791109589261e-07 1.06845659312697e-07 2.02225581949648e-07 3.02535099485185e-07 3.11957552477906e-08 9.15881915538412e-08 9.18891121954120e-07 3.70106500980225e-07 2.25779726927071e-07 2.86067288473873e-07 5.66382866246259e-07 4.26632108086086e-07 4.53045634671475e-07 1.17973378714372e-06 3.40969918417227e-07 2.48643473538260e-07 2.64505922988546e-07 2.38444406096982e-07 3.47101823144428e-07 3.37625374999722e-07 3.20790426924069e-07 5.02178252920690e-08 1.73576015527609e-07 8.57402376593969e-07 1.80131811857122e-07 2.76964595681315e-07 2.14838038341036e-07 2.21053263051776e-07 1.59406260405821e-07 4.59614264881235e-08 3.78789455759776e-07 2.58966590318316e-07 7.75696011578299e-08 3.39990416320565e-07 3.24572509489827e-07 3.52020828992088e-08 6.49912862168267e-08 2.22828739301052e-07 2.13473046057573e-07 1.70720547021041e-07 2.19582224668132e-07 2.05914598785446e-07 1.14899310738254e-06 1.03415047080757e-07 1.89177690522258e-06 2.24175047702725e-07 3.76150153666139e-07 9.18124634120261e-08 2.27678254839140e-07 8.61346207114181e-08 3.38947999645138e-06 1.71880093129416e-07 2.22461873169689e-07 3.72427593494344e-08 6.76102058093114e-08 1.13163515787091e-06 7.04052219453715e-07 3.28310827940334e-07 2.12060821359437e-07 2.68576701610855e-07 2.04744061114503e-07 1.14622616867334e-07 4.35675529886048e-08 5.29665131717990e-08 3.50574437154752e-08 5.32920831968263e-08 1.04801149974382e-07 2.08316009852988e-07 2.77349913208742e-07 1.48756450473382e-07 3.78517042358300e-07 1.19222278136494e-07 4.57902170141890e-08 2.03249187200450e-07 9.32437812713631e-08 6.61503340988668e-07 1.01572927594225e-06 3.26294032932256e-07 2.26313604682662e-07 7.01012285236915e-08 7.61666326540900e-08 4.16954886967803e-08 4.41719683698357e-08 4.02549730011751e-08 4.41603434482274e-08 3.50371730851861e-08 3.00718061774876e-07 3.50372423542925e-08 5.32741630316562e-08 2.09046711312522e-07 3.75611845531339e-06 2.26535469768828e-07 4.62710159517236e-07 5.55357457448765e-07 4.16702305525217e-07 2.05922476618442e-07 2.06490274401431e-07 2.33754328058605e-07 1.66615319203810e-07 2.13390792614979e-07 2.54792444311713e-07 4.20241426628409e-07 6.95047952441784e-07 6.02254152247896e-07 1.56218004764843e-07 1.99836446669293e-07 1.62974708502310e-07 2.93420921132526e-07 1.67909832369442e-07 1.53692619622575e-07 8.89709805825161e-08 1.64148574413349e-07 1.82871518257336e-07 1.99566615308843e-07 1.59784291140960e-07 1.87893662090374e-07 2.77364481028229e-07 1.10443572547260e-07 2.18556580353372e-07 1.83932131011210e-07 7.94652011731045e-08 2.43919458395486e-07 1.59781205439559e-07 1.94642054497664e-07 1.29989372686070e-07 1.90910393259075e-07 2.84452061601644e-07 3.30006526167654e-07 1.93485493531741e-07 2.40209860863182e-07 4.15333943239071e-07 2.91343651778087e-07 2.58377576473351e-07 1.81274762632482e-07 1.88893039486970e-07 2.19428417763272e-07 2.20994023873646e-07 2.27950728874121e-07 1.64400439994395e-07 1.00341668297253e-07 1.67577483763212e-07 5.61980802260245e-08 3.04539633123467e-08 3.19018898206730e-08 3.89504322796163e-08 3.19941498021468e-07 5.41874921040340e-06 1.01776790218898e-06 1.29079721421378e-06 5.77887058141474e-07 2.79939362285509e-07 5.55989804582382e-08 2.11144624551603e-07 5.73140726411827e-08 5.35992572193921e-08 2.80066251579433e-07 1.76964657359828e-07 3.25199602895421e-07 2.18271466195228e-07 1.80628024038326e-07 4.69550563668357e-08 1.48055689005769e-07 1.82317859358405e-07 1.33063533148151e-07 2.62672490298873e-08 2.52416541944235e-08 2.08244390466210e-07 3.06261128674104e-07 2.18183988930487e-07 1.32114003617060e-07 3.13731744862144e-07 2.78980205382911e-07 2.42110700965470e-08 1.28818767334643e-07 3.48416502648141e-07 1.43250842379859e-07 2.58790299254369e-08 2.36803673262810e-08 2.54679999490770e-08 1.53423624973069e-07 2.11044574009824e-07 2.45219073821534e-08 5.40329423903049e-08 4.07828910547019e-08 2.86866659397290e-08 5.74108869690081e-08 3.17780519921456e-08 2.89072270765441e-07 6.46668413187508e-08 3.89801393203052e-07 1.62322978572959e-07 2.69026419637955e-07 4.76120100475985e-07 5.32185045407108e-07 1.57575408820348e-07 2.08858600548085e-07 1.87565977660685e-07 2.01108310997773e-07 3.95620143987532e-08 5.24866345380986e-08 8.64930520826212e-08 9.74072997804584e-07 2.54439638933078e-08 1.00154777975012e-07 9.42429455464106e-07 2.23088555779751e-07 2.02097796370716e-07 1.99163165408265e-07 9.26536634692885e-08 1.31298738607173e-07 1.97726692783641e-07 2.28150683478771e-07 2.17170907865184e-07 2.69677497220439e-08 1.54765400027711e-07 6.26255760215395e-08 1.46771827369792e-07 1.81515822529873e-07 1.72918459779846e-07 8.15990146285526e-08 9.85514009220808e-08 7.03396855430348e-07 5.93657045438661e-07 1.51834395684521e-07 9.76927764035926e-08 1.18527867299870e-07 2.71435324116586e-08 5.68571003566081e-08 1.65983256102705e-07 2.29129793972797e-07 5.88646431511064e-08 3.08684402204026e-05 2.38265317337181e-06 4.30752744717656e-07 1.04689461805175e-07 2.32270648752108e-07 6.07211466407868e-07 1.95341105985221e-08 7.38231690963101e-08 1.95129857199575e-07 4.01671898332107e-08 4.75072551754564e-08 2.49046064060719e-06 1.78142428447807e-07 2.60935684174315e-07 4.29594269700864e-08 1.14070714922750e-07 5.26390027271695e-08 6.74132420131039e-08 2.11045265009953e-07 7.27021148761358e-07 2.83886081059763e-07 2.76343292567963e-08 1.61294742863238e-07 1.83304573271511e-07 2.45251911632262e-07 9.18095053702886e-07 9.40457085677553e-07 2.90451584499496e-07 1.04003175628026e-07 1.08284695915254e-07 5.44402482199441e-08 2.02578013696944e-08 5.88615942025308e-08 1.04406254724335e-07 1.20598226687063e-07 5.71264670628078e-07 3.15144191075623e-07 2.23052176438872e-08 2.98936409995515e-08 2.92428609360162e-07 2.47505388371339e-07 2.72866577624107e-07 2.69881858030521e-07 1.85519336468060e-07 2.56402576998181e-07 8.88653855726949e-08 1.23281438816645e-07 3.74059740200056e-08 3.63466577344003e-08 1.20887062612203e-06 5.31728280982040e-07 2.22245937870703e-08 1.24471844746278e-07 5.11735373064063e-07 3.13008213548308e-07 5.70247343660301e-08 7.23194564373494e-07 1.79616235944090e-07 6.78737172874271e-08 1.87999018332358e-07 1.56051038058590e-07 2.31029093824182e-08 3.65957708093627e-08 5.13581582166058e-07 2.55008648105981e-08 1.44166238137747e-07 3.81609462756446e-07 2.16242665285891e-07 2.34087134829968e-07 2.55408939395098e-07 5.31844204547311e-08 1.37230800917903e-07 2.24923680386313e-07 7.91242025449375e-08 1.56574476334133e-07 1.34926252415438e-07 1.70013819330808e-08 1.48130847036606e-07 1.10651211565701e-07 1.58123074045499e-07 1.47865663105776e-07 1.14316450201195e-07 2.02955526741989e-08 1.49518466142608e-07 2.99469635848321e-08 4.06175629714119e-07 2.32871553385763e-07 1.70948094081342e-07 1.86984334344187e-07 1.54774299548728e-07 1.27005955203776e-07 7.29605614875902e-08 4.26639317987837e-08 5.91930531596668e-08 1.50666658228087e-08 4.86748534643297e-08 1.64538615062307e-08 1.32252962938291e-07 1.06729078335828e-07 1.39785078669013e-07 1.39779800669610e-07 9.26422941859900e-08 1.13233915195479e-07 8.32946711657419e-08 1.67451405167575e-07 3.65621117891888e-08 2.21661117907828e-07 3.65652178907218e-08 1.41441861581090e-06 3.30075312403152e-07 2.05346680636497e-08 2.16432978289422e-07 1.92694668921994e-07 1.99379501668891e-07 2.60904461669433e-07 2.16709099204294e-07 1.33136064843243e-07 1.52413473502972e-07 7.53889226907776e-07 3.22036453180506e-07 1.68931528429636e-07 1.04094510285934e-07 1.60098934336117e-07 1.02657996503878e-07 6.83661821001145e-08 1.61931255758191e-07 2.01320024686194e-07 1.07534006069169e-07 1.07910634894973e-07 9.46522813533042e-08 1.66743437525985e-07 1.78365196465516e-07 1.90349497426267e-07 1.99051143944893e-07 1.10969246755729e-07 1.11264782143939e-07 1.02006294022338e-07 1.24767050443006e-07 1.04932154146443e-07 1.03659587531759e-07 4.90478970104965e-08 9.01107885624077e-08 9.30802687007756e-08 2.06842405795697e-07 1.53448550376276e-07 9.79061221486547e-08 8.26140384317179e-08 1.50146254483116e-07 1.40136146748372e-07 1.56837338087257e-07 1.76198808159403e-07 1.99122966368083e-07 1.23858764266714e-07 1.06727895602262e-07 8.15204687804434e-08 1.88227798887152e-08 2.31668781894091e-08 7.67325491571661e-07 1.97158231154847e-07 1.04232262587474e-07 8.81089549804027e-09 1.09695696650620e-08 3.67828021042941e-07 2.42873900856430e-07 9.30400519863338e-08 1.22815336391232e-08 1.04498084973760e-07 4.13726864269242e-07 1.28584375991528e-08 1.20376581165868e-07 1.07046398186240e-07 5.96207309583810e-08 3.66763563633301e-08 1.21422552113772e-07 1.39822102904246e-07 1.58475758239753e-07 8.54716186106630e-08 9.47107273229749e-08 1.57282457487923e-07 2.22341833330773e-07 1.47297286955243e-07 2.19435143761748e-07 1.39688617089499e-07 7.24259126481027e-08 7.09641458863346e-08 1.19226547380480e-07 7.87372467318109e-08 9.72314598010880e-08 7.74647075656411e-09 9.47412998435404e-08 1.16751285273194e-07 1.13487779361823e-07 1.13827758524977e-07 2.72522446715463e-07 8.16170870703966e-08 8.72321297381038e-08 9.95784392252335e-08 2.65989252708394e-09 1.06630932742284e-07 9.36921419305549e-08 8.41656329617571e-08 1.30269792124746e-08 4.86904164038956e-06 1.01469686899418e-07 1.47172552045969e-07 1.11949067863535e-07 9.34802107168088e-08 6.41098286680338e-08 6.68095594366830e-09 4.65659962399765e-08 1.74321722504626e-07 1.53177157686198e-07 1.72679939394816e-07 9.26791009109865e-08 7.38280843033631e-09 1.21431764801520e-08 1.83474589517062e-08 5.49758746890643e-08 5.49686356365556e-08 5.41396143667257e-07 1.02078716839878e-08 1.46280082306786e-07 9.20039209747377e-08 1.07464173701763e-08 4.37249887631680e-08 1.20696543908951e-07 7.37023067237918e-08 1.54370995646110e-07 8.75880053587604e-08 1.38972473988507e-07 1.50011697718075e-07 1.13900910702895e-07 7.30960487245964e-08 1.06352204500379e-07 7.15892552073097e-09 1.26382007766409e-08 2.34492999966371e-07 9.25652500580458e-08 8.91104525001921e-08 1.04346566674604e-08 7.96833204055166e-08 3.41626685510968e-07 1.46859973263572e-07 6.99097620123092e-08 5.60565018753087e-08 9.18716519344181e-08 5.82078430390537e-09 8.51757309259611e-08 1.41028716092150e-07 7.10210717526897e-09 3.02205722277794e-08 2.76205242367368e-07 9.08403872147274e-08 8.55641175181640e-08 8.07674139440669e-08 5.64950026938399e-09 1.47871928050032e-07 1.37623718221666e-07 9.60980796219824e-08 9.05395061229061e-09 3.58713661087815e-07 3.78246981154481e-07 1.97627162656081e-08 4.78463482905684e-08 5.47976120635378e-07 5.98012738422856e-07 1.38288635243591e-07 3.97209746106909e-08 1.04405402152745e-07 1.64230983323839e-08 2.14721179480984e-08 4.85083210883807e-08 1.22646011220379e-06 8.39456826640735e-09 8.27662116573820e-08 3.58891263221149e-07 9.16048888640066e-08 1.21278839928491e-07 2.31054125718236e-07 1.00889365297461e-07 1.19358834432565e-07 2.43427211256917e-07 9.11020950715102e-08 1.38162844699562e-07 8.00915682468241e-08 4.98258405386454e-09 7.30080219716715e-08 1.52701681888474e-07 2.93328698184570e-07 1.35353313498113e-07 4.59682925254202e-08 9.08782411223864e-08 2.20927979357592e-08 9.05503229704100e-08 6.68343694641667e-08 7.33025736057753e-08 7.49958147508063e-08 6.22824091009223e-09 8.02682015058001e-06 3.67877032868707e-07 7.19496678750717e-08 3.17758490462365e-09 5.75563157661276e-09 3.24272951280416e-09 1.00381201383279e-07 1.88260239049035e-07 7.07194739983604e-08 4.68947848174950e-09 4.16252458503278e-09 7.94576959843098e-08 2.74009776209153e-07 1.42430916804990e-07 1.26235913248699e-07 1.39626029880374e-07 1.16782761195100e-07 1.00256563902946e-07 -2.95101260456139e-09 6.83432403678117e-08 1.27348806727558e-07 5.96766339731236e-08 1.03604721020808e-07 1.21085249476580e-07 6.80561072346092e-08 2.39948064835149e-09 1.00688731186191e-08 2.43035685127838e-08 4.13254891501583e-08 9.63544005596039e-09 2.53883818143423e-07 7.44890597640385e-07];
w0=0.002;
F=2*(pi^2)*(k^2).*z_diff.*Phi;
x0 = linspace(-0.02,0.02,Nx);y0=x0;[X0,Y0] = meshgrid(x0,y0);
Uin=exp(-(X0.^2+Y0.^2)/w0^2);
x = x + z_diff(1)*tan(beta);
screen1 = exp(1i*((Kx.*x) + (Ky.*y))).*delfx.*delfy.*sqrt(F(1)).*R ;
Uout = Uin.*exp(1i.*screen1);
c=[0.740664357812470 0.715162315217582 0.689780546528124 0.664556687838984 0.639501229779350 0.614618312979130 0.589909677254809 0.565375929219662 0.541017064806704 0.516832720551119 0.492822307973243 0.468985091286926 0.445320235117717 0.421826835235231 0.398503939126698 0.375350560217132 0.352365687964806 0.329548295192595 0.306897343515746 0.284411787427262 0.262090577416753 0.239932662380474 0.217936991503006 0.196102515739251 0.174428188990141 0.152912969040777 0.131555818312352 0.110355704466664 0.0893116008928944 0.0684224870996102 0.0476873490298864 0.0271051793136574 0.00667497746850089 0.0136042499421828 0.0337334891863653 0.0537137192700918 0.0735459118688980 0.0932310312800026 0.112770034392025 0.132163870669524 0.151413482150099 0.170519803452171 0.189483761791847 0.208306277007520 0.226988261591059 0.245530620724636 0.263934252322323 0.282200047075789 0.300328888503445 0.318321653002534 0.336179209903699 0.353902421527639 0.371492143243500 0.388949223528713 0.406274504030009 0.423468819625392 0.440532998486862 0.457467862143721 0.474274225546305 0.490952897130006 0.507504678879476 0.523930366392895 0.540230748946220 0.556406609557339 0.572458725050048 0.588387866117797 0.604194797387153 0.619880277480917 0.635445059080876 0.650889888990134 0.666215508194993 0.681422651926368 0.696512049720699 0.711484425480339 0.726340497533411 0.741080978693105 0.755706576316408 0.770217992362264 0.784615923449129 0.798901060911951 0.813074090858528 0.827135694225279 0.841086546832386 0.854927319438336 0.868658677793846 0.882281282695167 0.895795790036781 0.909202850863477 0.922503111421817 0.935697213210995 0.948785793033077 0.961769483042646 0.974648910795838 0.987424699298783 1.00009746705545 1.01266782811491 1.02513639211797 1.03750376434332 1.04977054575300 1.06193733303735 1.07400471865938 1.08597329089862 1.09784363389434 1.10961632768826 1.12129194826677 1.13287106760249 1.14435425369543 1.15574207061353 1.16703507853271 1.17823383377643 1.18933888885472 1.20035079250267 1.21127008971854 1.22209732180122 1.23283302638735 1.24347773748787 1.25403198552414 1.26449629736359 1.27487119635488 1.28515720236266 1.29535483180181 1.30546459767133 1.31548700958769 1.32542257381781 1.33527179331163 1.34503516773420 1.35471319349739 1.36430636379121 1.37381516861470 1.38324009480640 1.39258162607448 1.40184024302645 1.41101642319850 1.42011064108442 1.42912336816425 1.43805507293243 1.44690622092571 1.45567727475060 1.46436869411057 1.47298093583279 1.48151445389465 1.48996969944983 1.49834712085410 1.50664716369079 1.51487027079592 1.52301688228302 1.53108743556759 1.53908236539135 1.54700210384610 1.55484708039729 1.56261772190731 1.57031445265850 1.57793769437581 1.58548786624928 1.59296538495611 1.60037066468257 1.60770411714556 1.61496615161393 1.62215717492952 1.62927759152798 1.63632780345927 1.64330821040796 1.65021920971321 1.65706119638862 1.66383456314170 1.67053970039319 1.67717699629614 1.68374683675467 1.69024960544263 1.69668568382193 1.70305545116068 1.70935928455115 1.71559755892740 1.72177064708287 1.72787891968756 1.73392274530517 1.73990249040993 1.74581851940328 1.75167119463032 1.75746087639608 1.76318792298160 1.76885269065981 1.77445553371120 1.77999680443936 1.78547685318630 1.79089602834756 1.79625467638721 1.80155314185264 1.80679176738913 1.81197089375438 1.81709085983270 1.82215200264920 1.82715465738367 1.83209915738443 1.83698583418192 1.84181501750219 1.84658703528021 1.85130221367304 1.85596087707287 1.86056334811985 1.86510994771484 1.86960099503199 1.87403680753115 1.87841770097023 1.88274398941727 1.88701598526258 1.89123399923051 1.89539834039132 1.89950931617273 1.90356723237146 1.90757239316461 1.91152510112087 1.91542565721170 1.91927436082231 1.92307150976254 1.92681740027765 1.93051232705897 1.93415658325440 1.93775046047891 1.94129424882478 1.94478823687186 1.94823271169764 1.95162795888723 1.95497426254328 1.95827190529575 1.96152116831153 1.96472233130413 1.96787567254306 1.97098146886325 1.97403999567435 1.97705152696986 1.98001633533631 1.98293469196218 1.98580686664685 1.98863312780943 1.99141374249746 1.99414897639556 1.99683909383401 1.99948435779718 2.00208502993198 2.00464137055607 2.00715363866619 2.00962209194621 2.01204698677524 2.01442857823560 2.01676712012071 2.01906286494297 2.02131606394144 2.02352696708957 2.02569582310279 2.02782287944605 2.02990838234126 2.03195257677470 2.03395570650435 2.03591801406711 2.03783974078601 2.03972112677735 2.04156241095768 2.04336383105087 2.04512562359498 2.04684802394913 2.04853126630031 2.05017558367013 2.05178120792145 2.05334836976503 2.05487729876606 2.05636822335072 2.05782137081251 2.05923696731876 2.06061523791685 2.06195640654055 2.06326069601621 2.06452832806891 2.06575952332861 2.06695450133616 2.06811348054936 2.06923667834885 2.07032431104407 2.07137659387907 2.07239374103836 2.07337596565262 2.07432347980443 2.07523649453394 2.07611521984447 2.07695986470806 2.07777063707106 2.07854774385950 2.07929139098462 2.08000178334822 2.08067912484798 2.08132361838281 2.08193546585808 2.08251486819086 2.08306202531507 2.08357713618662 2.08406039878854 2.08451201013601 2.08493216628138 2.08532106231914 2.08567889239087 2.08600584969017 2.08630212646748 2.08656791403493 2.08680340277114 2.08700878212594 2.08718424062516 2.08732996587524 2.08744614456794 2.08753296248490 2.08759060450230 2.08761925459532 2.08761909584274 2.08759031043135 2.08753307966046 2.08744758394630 2.08733400282638 2.08719251496389 2.08702329815202 2.08682652931821 2.08660238452849 2.08635103899165 2.08607266706347 2.08576744225093 2.08543553721630 2.08507712378131 2.08469237293121 2.08428145481885 2.08384453876873 2.08338179328099 2.08289338603538 2.08237948389527 2.08184025291152 2.08127585832643 2.08068646457760 2.08007223530177 2.07943333333869 2.07876992073487 2.07808215874743 2.07737020784777 2.07663422772538 2.07587437729149 2.07509081468279 2.07428369726507 2.07345318163688 2.07259942363312 2.07172257832864 2.07082280004183 2.06990024233815 2.06895505803365 2.06798739919850 2.06699741716044 2.06598526250827 2.06495108509530 2.06389503404273 2.06281725774310 2.06171790386362 2.06059711934957 2.05945505042762 2.05829184260918 2.05710764069365 2.05590258877174 2.05467683022873 2.05343050774771 2.05216376331278 2.05087673821232 2.04956957304210 2.04824240770851 2.04689538143169 2.04552863274867 2.04414229951646 2.04273651891521 2.04131142745123 2.03986716096009 2.03840385460964 2.03692164290309 2.03542065968197 2.03390103812916 2.03236291077188 2.03080640948460 2.02923166549207 2.02763880937220 2.02602797105897 2.02439927984538 2.02275286438630 2.02108885270135 2.01940737217775 2.01770854957318 2.01599251101859 2.01425938202100 2.01250928746633 2.01074235162217 2.00895869814052 2.00715845006058 2.00534172981146 2.00350865921493 2.00165935948813 1.99979395124624 1.99791255450517 1.99601528868428 1.99410227260896 1.99217362451332 1.99022946204283 1.98826990225688 1.98629506163147 1.98430505606170 1.98230000086442 1.98028001078079 1.97824519997880 1.97619568205582 1.97413157004115 1.97205297639850 1.96996001302854 1.96785279127132 1.96573142190885 1.96359601516744 1.96144668072028 1.95928352768979 1.95710666465011 1.95491619962948 1.95271224011267 1.95049489304337 1.94826426482658 1.94602046133099 1.94376358789132 1.94149374931069 1.93921104986296 1.93691559329504 1.93460748282926 1.93228682116561 1.92995371048410 1.92760825244698 1.92525054820109 1.92288069838009 1.92049880310668 1.91810496199492 1.91569927415240 1.91328183818251 1.91085275218661 1.90841211376627 1.90596002002548 1.90349656757275 1.90102185252339 1.89853597050162 1.89603901664270 1.89353108559514 1.89101227152279 1.88848266810698 1.88594236854864 1.88339146557039 1.88083005141866 1.87825821786576 1.87567605621199 1.87308365728765 1.87048111145519 1.86786850861116 1.86524593818833 1.86261348915771 1.85997125003053 1.85731930886031 1.85465775324484 1.85198667032819 1.84930614680269 1.84661626891091 1.84391712244766 1.84120879276190 1.83849136475875 1.83576492290140 1.83302955121309 1.83028533327899 1.82753235224814 1.82477069083540 1.82200043132329 1.81922165556395 1.81643444498099 1.81363888057138 1.81083504290734 1.80802301213817 1.80520286799215 1.80237468977836 1.79953855638852 1.79669454629885 1.79384273757188 1.79098320785825 1.78811603439854 1.78524129402510 1.78235906316378 1.77946941783578 1.77657243365938 1.77366818585177 1.77075674923075 1.76783819821655 1.76491260683352 1.76198004871193 1.75904059708966 1.75609432481398 1.75314130434320 1.75018160774846 1.74721530671537 1.74424247254577 1.74126317615938 1.73827748809551 1.73528547851471 1.73228721720050 1.72928277356095 1.72627221663041 1.72325561507115 1.72023303717496 1.71720455086485 1.71417022369661 1.71113012286052 1.70808431518289 1.70503286712770 1.70197584479823 1.69891331393861 1.69584533993546 1.69277198781941 1.68969332226677 1.68660940760100 1.68352030779434 1.68042608646938 1.67732680690054 1.67422253201569 1.67111332439765 1.66799924628574 1.66488035957729 1.66175672582918 1.65862840625934 1.65549546174827 1.65235795284053 1.64921593974624 1.64606948234258 1.64291864017527 1.63976347246002 1.63660403808406 1.63344039560754 1.63027260326505 1.62710071896701 1.62392480030119 1.62074490453409 1.61756108861240 1.61437340916446 1.61118192250163 1.60798668461974 1.60478775120050 1.60158517761291 1.59837901891464 1.59516932985347 1.59195616486864 1.58873957809224 1.58551962335059 1.58229635416566 1.57906982375634 1.57584008503991 1.57260719063331 1.56937119285456 1.56613214372404 1.56289009496590 1.55964509800932 1.55639720398990 1.55314646375097 1.54989292784488 1.54663664653434 1.54337766979374 1.54011604731041 1.53685182848594 1.53358506243751 1.53031579799910 1.52704408372284 1.52376996788025 1.52049349846351 1.51721472318676 1.51393368948733 1.51065044452699 1.50736503519323 1.50407750810048 1.50078790959138 1.49749628573799 1.49420268234301 1.49090714494105 1.48760971879982 1.48431044892133 1.48100938004314 1.47770655663956 1.47440202292281 1.47109582284426 1.46778800009561 1.46447859811008 1.46116766006355 1.45785522887583 1.45454134721172 1.45122605748225 1.44790940184585 1.44459142220945 1.44127216022968 1.43795165731401 1.43462995462187 1.43130709306582 1.42798311331269 1.42465805578467 1.42133196066046 1.41800486787641 1.41467681712758 1.41134784786894 1.40801799931637 1.40468731044786 1.40135582000454 1.39802356649183 1.39469058818047 1.39135692310765 1.38802260907807 1.38468768366504 1.38135218421152 1.37801614783119 1.37467961140955 1.37134261160493 1.36800518484960 1.36466736735075 1.36132919509161 1.35799070383243 1.35465192911156 1.35131290624645 1.34797367033472 1.34463425625514 1.34129469866868 1.33795503201952 1.33461529053606 1.33127550823193 1.32793571890697 1.32459595614830 1.32125625333121 1.31791664362027 1.31457715997020 1.31123783512696 1.30789870162865 1.30455979180654 1.30122113778599 1.29788277148748 1.29454472462753 1.29120702871964 1.28786971507532 1.28453281480497 1.28119635881886 1.27786037782809 1.27452490234548 1.27118996268656 1.26785558897046 1.26452181112088 1.26118865886698 1.25785616174431 1.25452434909574 1.25119325007237 1.24786289363441 1.24453330855215 1.24120452340678 1.23787656659136 1.23454946631169 1.23122325058718 1.22789794725176 1.22457358395477 1.22125018816181 1.21792778715567 1.21460640803712 1.21128607772588 1.20796682296139 1.20464867030376 1.20133164613454 1.19801577665766 1.19470108790021 1.19138760571334 1.18807535577308 1.18476436358118 1.18145465446596 1.17814625358312 1.17483918591663 1.17153347627945 1.16822914931448 1.16492622949528 1.16162474112694 1.15832470834688 1.15502615512566 1.15172910526776 1.14843358241246 1.14513961003454 1.14184721144515 1.13855640979258 1.13526722806305 1.13197968908148 1.12869381551230 1.12540962986023 1.12212715447104 1.11884641153231 1.11556742307426 1.11229021097045 1.10901479693858 1.10574120254124 1.10246944918668 1.09919955812955 1.09593155047166 1.09266544716271 1.08940126900108 1.08613903663452 1.08287877056091 1.07962049112901 1.07636421853917 1.07310997284407 1.06985777394945 1.06660764161482 1.06335959545421 1.06011365493683 1.05686983938786 1.05362816798911 1.05038865977972 1.04715133365691 1.04391620837666 1.04068330255439 1.03745263466568 1.03422422304698 1.03099808589625 1.02777424127369 1.02455270710241 1.02133350116911 1.01811664112476 1.01490214448529 1.01169002863224 1.00848031081345 1.00527300814371 1.00206813760545 0.998865716049361 0.995665760195108 0.992468286631939 0.989273311819364 0.986080852087796 0.982890923639205 0.979703542547760 0.976518724760467 0.973336486097822 0.970156842254431 0.966979808799657 0.963805401178249 0.960633634710965 0.957464524595207 0.954298085905637 0.951134333594803 0.947973282493756 0.944814947312659 0.941659342641416 0.938506482950264 0.935356382590394 0.932209055794548 0.929064516677626 0.925922779237284 0.922783857354535 0.919647764794513 0.916514553007848 0.913626501586297 0.957181910437377 1.18507611517074];
Ri=z_diff./cos(beta);
screens = zeros(Nx,Nx,length(F)-1);
for i = 2:length(F)
x = x + z_diff(i)*tan(beta);
screens(:,:,i)= screens(:, :, i-1) + exp(1i*((Kx.*x)+(Ky.*y))).*delfx.*delfy.*sqrt(F(i)).*R;
Hi = exp(1i*Kz*Ri(i) – c(i).*Ri(i));
Ui = fftshift(fft2(Uout));
Ui = Hi.*Ui;
Ui = ifft2(ifftshift(Ui));
Uio = Ui.*exp(1i.*screens(:,:,i));
I = Uio.*conj(Uio);
Uout = Uio;
end
% to calculate SigmaI
A1=0;A2=0;
for i1=1:Nx
for i2=1:Nx
I1 = I(i1,i2)^2 ;
A1 = A1 + I1 ;
end
end
for j1=1:Nx
for j2=1:Nx
I2 = I(j1,j2) ;
A2 = A2 + I2;
end
end
SI = abs(((A1/Nx)/((A2/Nx)^2)) – 1);
%to calculate BER
syms u
PI = (1/(u*sqrt(2*pi*SI)))*exp(-((log(u) + SI )^2)/(2*SI)) ;
SNR0 = 1;
SNR = SNR0/sqrt(1+SI*SNR0) ;
fun = PI*erfc(real((SNR.*u)/(2*sqrt(2))));
ff = matlabFunction(fun,’Vars’,u);
BER = (0.5*integral(ff,0,Inf)) summation MATLAB Answers — New Questions
Placing a Peltier in a cooling and hot air source
I want to place a peltier module in a hot air source as well as a cool air source before are the images of the two different systems
the above diagram is for the hot air source
the above is the diagram for the cooling air source.
1.how do i include a peltier module in this?I want to place a peltier module in a hot air source as well as a cool air source before are the images of the two different systems
the above diagram is for the hot air source
the above is the diagram for the cooling air source.
1.how do i include a peltier module in this? I want to place a peltier module in a hot air source as well as a cool air source before are the images of the two different systems
the above diagram is for the hot air source
the above is the diagram for the cooling air source.
1.how do i include a peltier module in this? peltier, heat, temperature, air sources, control MATLAB Answers — New Questions
Error of ‘Value’ must be a double scalar within the range of ‘Limits’ and Error using -. Arrays have incompatible sizes for this operation.
This is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
endThis is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
end This is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
end ni daq MATLAB Answers — New Questions
no definition for plot3
It’s ok to use plot3 in MATLAB script,problems comes when I try to packet them in my function ‘PlotDampRoots’:says plot3 not defined.what suppose I do?It’s ok to use plot3 in MATLAB script,problems comes when I try to packet them in my function ‘PlotDampRoots’:says plot3 not defined.what suppose I do? It’s ok to use plot3 in MATLAB script,problems comes when I try to packet them in my function ‘PlotDampRoots’:says plot3 not defined.what suppose I do? no definition error MATLAB Answers — New Questions
adding linear interpolation to a fitness equation
So I’m creating a dynamic state-variable model and I want to add in a forgetting rate for an informational state, however that’ll make the values non-integers and thus I need to do linear interpolation. How do I add that in to my fitness equation?
Sorry for the overwhelming amount of code
%constants
m1=0.9;
m2=0.3;
n1=0.3;
n2=0.9;
b=0.9;
crit=3;
cap=15;
term=20;
%arrays and zeros
opt=zeros(cap,cap, cap,term);
Fd=zeros(cap, cap, cap,term);
Fdd=zeros(cap,cap,cap,term);
Fdb=zeros(cap,cap, cap,term);
Fdbb=zeros(cap,cap,cap,term);
Ft=zeros(cap,cap,cap,term);
x=linspace(1,cap,cap)’;
z=linspace(1,cap,cap)’;
y=linspace(1,cap,cap)’;
f=@(x,y) x-y;
M=f(z.’,y);
p=zeros(size(M));
p2=zeros(size(M));
p3=zeros(size(M));
p4=zeros(size(M));
p5=zeros(size(M));
%z and y
z1=z+1; %dem went to patch 1 and found food
z1(z1>cap)=cap;
z2=z-1; %dem went to patch 1 and didn’t find food
z2(z2<1)=1;
zp=(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
y1=y+1; %dem went to patch 2 and found food
y1(y1>cap)=cap;
y2=y-1; %dem went to patch 2 and didn’t find food
y2(y2<1)=1;
yp=(y1+1); %dem went to patch 2 and found food; obs went to patch 2 and found food
yp(yp>cap)=cap;
ypp=(y1-1); %dem went to patch 2 and found food; obs went to patch 2 and didn’t food
ypp(ypp<1)=1;
yd=(y2+1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and found food
yd(yd>cap)=cap;
ydd=(y2-1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and didn’t find food
ydd(ydd<1)=1;
yg=(y+1); %obs went to patch 2 and found food
yg(yg>cap)=cap;
ygg=(y-1); %obs went to patch 2 and didn’t find food
ygg(ygg<1)=1;
%physical states
xp=x-1-1+3; %obs watched dem and found food
xp(xp>cap)=cap;
xpp=x-1-1; %obs watched dem and didn’t find food
xpp(xpp<1)=1;
xd=x-1+3; %obs didn’t watch and found food
xd(xd>cap)=cap;
xdd=x-1; %obs didn’t watch and didn’t find food
xdd(xdd<1)=1;
%specify fitness
Fd(x<=crit,:, :, :)=0;
Fd(x>crit,:,:,:)=1;
Fdb(x<=crit,:,:,:)=0;
Fdb(x>crit,:,:,:)=1;
%specify prob matrix of going to patch 1 for obs
for j=1:15
for k=1:15
if M(j,z1(k))>0
p(j,z1(k))=0.9;
elseif M(j,z1(k))<0
p(j,z1(k))=0.1;
else
p(j,z1(k))=0.5;
end
if M(j,z2(k))>0
p2(j,z2(k))=0.9;
elseif M(j,z2(k))<0
p2(j,z2(k))=0.1;
else
p2(j,z2(k))=0.5;
end
if M(y1(j),k)>0
p3(y1(j),k)=0.9;
elseif M(y1(j),k)<0
p3(y1(j),k)=0.1;
else
p3(y1(j),k)=0.5;
end
if M(y2(j),k)>0
p4(y2(j),k)=0.9;
elseif M(y2(j),k)<0
p4(y2(j),k)=0.1;
else
p4(y2(j),k)=0.5;
end
if M(y(j),z(k))>0
p5(y(j),z(k))=0.9;
elseif M(y(j),z(k))<0
p5(y(j),z(k))=0.1;
else
p5(y(j),z(k))=0.5;
end
end
end
%fitness equations for watching a dem (Fdd) and not watching a dem (Fdbb)
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
Fdd(i,j,k,tt)= b*(…
m1*(…
p(j,z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+…
(1-p(j,z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+…
(1-m1)*(…
p2(j,z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+…
(1-p2(j,z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1))…
))+…
(1-b)*( …
m2*(…
p3(y1(j),k)*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ …
(1-p3(y1(j),k))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ …
(1-m2)*(p4(y2(j),k)*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+…
(1-p4(y2(j),k))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1))));
Fdbb(i,j,k,tt)= p5(j,k)*( …
n1*Fdb(xd(i),zg(j),y(k),tt+1) + (1-n1)*Fdb(xdd(i),zgg(j),y(k),tt+1) …
)+…
(1-p5(j,k))*( …
n2*Fdb(xd(i),z(j),yg(k),tt+1) + (1-n2)*Fdb(xdd(i),z(j),ygg(k),tt+1)) …
;
%optimal decision and fitness
if Fdd(i,j,k,tt)>Fdbb(i,j,k,tt)
opt(i,j,k,tt)=1;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
elseif Fdd(i,j,k,tt)<Fdbb(i,j,k,tt)
opt(i,j,k,tt)=2;
Ft(i,j,k,tt)=Fdbb(i,j,k,tt);
elseif Fdd(i,j,k,tt)==Fdbb(i,j,k,tt)
opt(i,j,k,tt)=3;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
end
end
end
end
end
I would like to add in a forgetting rate so that it looks more like this:
l=0.95;
zp=l*(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=l*(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=l*(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=l*(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=l*(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=l*(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
%this would be added to the y’s as well
How do I edit the fitness equation to add in linear interpolation?
note that Fdd is a 4-D matrix, because it has a physical state (x), two infomational states (z and y), and then time (t)
most of the interpolation I see modifies 1-D matricesSo I’m creating a dynamic state-variable model and I want to add in a forgetting rate for an informational state, however that’ll make the values non-integers and thus I need to do linear interpolation. How do I add that in to my fitness equation?
Sorry for the overwhelming amount of code
%constants
m1=0.9;
m2=0.3;
n1=0.3;
n2=0.9;
b=0.9;
crit=3;
cap=15;
term=20;
%arrays and zeros
opt=zeros(cap,cap, cap,term);
Fd=zeros(cap, cap, cap,term);
Fdd=zeros(cap,cap,cap,term);
Fdb=zeros(cap,cap, cap,term);
Fdbb=zeros(cap,cap,cap,term);
Ft=zeros(cap,cap,cap,term);
x=linspace(1,cap,cap)’;
z=linspace(1,cap,cap)’;
y=linspace(1,cap,cap)’;
f=@(x,y) x-y;
M=f(z.’,y);
p=zeros(size(M));
p2=zeros(size(M));
p3=zeros(size(M));
p4=zeros(size(M));
p5=zeros(size(M));
%z and y
z1=z+1; %dem went to patch 1 and found food
z1(z1>cap)=cap;
z2=z-1; %dem went to patch 1 and didn’t find food
z2(z2<1)=1;
zp=(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
y1=y+1; %dem went to patch 2 and found food
y1(y1>cap)=cap;
y2=y-1; %dem went to patch 2 and didn’t find food
y2(y2<1)=1;
yp=(y1+1); %dem went to patch 2 and found food; obs went to patch 2 and found food
yp(yp>cap)=cap;
ypp=(y1-1); %dem went to patch 2 and found food; obs went to patch 2 and didn’t food
ypp(ypp<1)=1;
yd=(y2+1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and found food
yd(yd>cap)=cap;
ydd=(y2-1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and didn’t find food
ydd(ydd<1)=1;
yg=(y+1); %obs went to patch 2 and found food
yg(yg>cap)=cap;
ygg=(y-1); %obs went to patch 2 and didn’t find food
ygg(ygg<1)=1;
%physical states
xp=x-1-1+3; %obs watched dem and found food
xp(xp>cap)=cap;
xpp=x-1-1; %obs watched dem and didn’t find food
xpp(xpp<1)=1;
xd=x-1+3; %obs didn’t watch and found food
xd(xd>cap)=cap;
xdd=x-1; %obs didn’t watch and didn’t find food
xdd(xdd<1)=1;
%specify fitness
Fd(x<=crit,:, :, :)=0;
Fd(x>crit,:,:,:)=1;
Fdb(x<=crit,:,:,:)=0;
Fdb(x>crit,:,:,:)=1;
%specify prob matrix of going to patch 1 for obs
for j=1:15
for k=1:15
if M(j,z1(k))>0
p(j,z1(k))=0.9;
elseif M(j,z1(k))<0
p(j,z1(k))=0.1;
else
p(j,z1(k))=0.5;
end
if M(j,z2(k))>0
p2(j,z2(k))=0.9;
elseif M(j,z2(k))<0
p2(j,z2(k))=0.1;
else
p2(j,z2(k))=0.5;
end
if M(y1(j),k)>0
p3(y1(j),k)=0.9;
elseif M(y1(j),k)<0
p3(y1(j),k)=0.1;
else
p3(y1(j),k)=0.5;
end
if M(y2(j),k)>0
p4(y2(j),k)=0.9;
elseif M(y2(j),k)<0
p4(y2(j),k)=0.1;
else
p4(y2(j),k)=0.5;
end
if M(y(j),z(k))>0
p5(y(j),z(k))=0.9;
elseif M(y(j),z(k))<0
p5(y(j),z(k))=0.1;
else
p5(y(j),z(k))=0.5;
end
end
end
%fitness equations for watching a dem (Fdd) and not watching a dem (Fdbb)
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
Fdd(i,j,k,tt)= b*(…
m1*(…
p(j,z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+…
(1-p(j,z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+…
(1-m1)*(…
p2(j,z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+…
(1-p2(j,z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1))…
))+…
(1-b)*( …
m2*(…
p3(y1(j),k)*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ …
(1-p3(y1(j),k))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ …
(1-m2)*(p4(y2(j),k)*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+…
(1-p4(y2(j),k))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1))));
Fdbb(i,j,k,tt)= p5(j,k)*( …
n1*Fdb(xd(i),zg(j),y(k),tt+1) + (1-n1)*Fdb(xdd(i),zgg(j),y(k),tt+1) …
)+…
(1-p5(j,k))*( …
n2*Fdb(xd(i),z(j),yg(k),tt+1) + (1-n2)*Fdb(xdd(i),z(j),ygg(k),tt+1)) …
;
%optimal decision and fitness
if Fdd(i,j,k,tt)>Fdbb(i,j,k,tt)
opt(i,j,k,tt)=1;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
elseif Fdd(i,j,k,tt)<Fdbb(i,j,k,tt)
opt(i,j,k,tt)=2;
Ft(i,j,k,tt)=Fdbb(i,j,k,tt);
elseif Fdd(i,j,k,tt)==Fdbb(i,j,k,tt)
opt(i,j,k,tt)=3;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
end
end
end
end
end
I would like to add in a forgetting rate so that it looks more like this:
l=0.95;
zp=l*(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=l*(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=l*(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=l*(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=l*(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=l*(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
%this would be added to the y’s as well
How do I edit the fitness equation to add in linear interpolation?
note that Fdd is a 4-D matrix, because it has a physical state (x), two infomational states (z and y), and then time (t)
most of the interpolation I see modifies 1-D matrices So I’m creating a dynamic state-variable model and I want to add in a forgetting rate for an informational state, however that’ll make the values non-integers and thus I need to do linear interpolation. How do I add that in to my fitness equation?
Sorry for the overwhelming amount of code
%constants
m1=0.9;
m2=0.3;
n1=0.3;
n2=0.9;
b=0.9;
crit=3;
cap=15;
term=20;
%arrays and zeros
opt=zeros(cap,cap, cap,term);
Fd=zeros(cap, cap, cap,term);
Fdd=zeros(cap,cap,cap,term);
Fdb=zeros(cap,cap, cap,term);
Fdbb=zeros(cap,cap,cap,term);
Ft=zeros(cap,cap,cap,term);
x=linspace(1,cap,cap)’;
z=linspace(1,cap,cap)’;
y=linspace(1,cap,cap)’;
f=@(x,y) x-y;
M=f(z.’,y);
p=zeros(size(M));
p2=zeros(size(M));
p3=zeros(size(M));
p4=zeros(size(M));
p5=zeros(size(M));
%z and y
z1=z+1; %dem went to patch 1 and found food
z1(z1>cap)=cap;
z2=z-1; %dem went to patch 1 and didn’t find food
z2(z2<1)=1;
zp=(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
y1=y+1; %dem went to patch 2 and found food
y1(y1>cap)=cap;
y2=y-1; %dem went to patch 2 and didn’t find food
y2(y2<1)=1;
yp=(y1+1); %dem went to patch 2 and found food; obs went to patch 2 and found food
yp(yp>cap)=cap;
ypp=(y1-1); %dem went to patch 2 and found food; obs went to patch 2 and didn’t food
ypp(ypp<1)=1;
yd=(y2+1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and found food
yd(yd>cap)=cap;
ydd=(y2-1); %dem went to patch 2 and didn’t find food; obs went to patch 2 and didn’t find food
ydd(ydd<1)=1;
yg=(y+1); %obs went to patch 2 and found food
yg(yg>cap)=cap;
ygg=(y-1); %obs went to patch 2 and didn’t find food
ygg(ygg<1)=1;
%physical states
xp=x-1-1+3; %obs watched dem and found food
xp(xp>cap)=cap;
xpp=x-1-1; %obs watched dem and didn’t find food
xpp(xpp<1)=1;
xd=x-1+3; %obs didn’t watch and found food
xd(xd>cap)=cap;
xdd=x-1; %obs didn’t watch and didn’t find food
xdd(xdd<1)=1;
%specify fitness
Fd(x<=crit,:, :, :)=0;
Fd(x>crit,:,:,:)=1;
Fdb(x<=crit,:,:,:)=0;
Fdb(x>crit,:,:,:)=1;
%specify prob matrix of going to patch 1 for obs
for j=1:15
for k=1:15
if M(j,z1(k))>0
p(j,z1(k))=0.9;
elseif M(j,z1(k))<0
p(j,z1(k))=0.1;
else
p(j,z1(k))=0.5;
end
if M(j,z2(k))>0
p2(j,z2(k))=0.9;
elseif M(j,z2(k))<0
p2(j,z2(k))=0.1;
else
p2(j,z2(k))=0.5;
end
if M(y1(j),k)>0
p3(y1(j),k)=0.9;
elseif M(y1(j),k)<0
p3(y1(j),k)=0.1;
else
p3(y1(j),k)=0.5;
end
if M(y2(j),k)>0
p4(y2(j),k)=0.9;
elseif M(y2(j),k)<0
p4(y2(j),k)=0.1;
else
p4(y2(j),k)=0.5;
end
if M(y(j),z(k))>0
p5(y(j),z(k))=0.9;
elseif M(y(j),z(k))<0
p5(y(j),z(k))=0.1;
else
p5(y(j),z(k))=0.5;
end
end
end
%fitness equations for watching a dem (Fdd) and not watching a dem (Fdbb)
for tt=19:-1:1
for i=1:15
for j=1:15
for k=1:15
Fdd(i,j,k,tt)= b*(…
m1*(…
p(j,z1(k))*(n1*Fd(xp(i),zp(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zpp(j),y(k),tt+1))+…
(1-p(j,z1(k)))*(n2*Fd(xp(i),z1(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z1(j),ygg(k),tt+1)))+…
(1-m1)*(…
p2(j,z2(k))*(n1*Fd(xp(i),zd(j),y(k),tt+1) + (1-n1)*Fd(xpp(i),zdd(j),y(k),tt+1))+…
(1-p2(j,z2(k)))*(n2*Fd(xp(i),z2(j),yg(k),tt+1) + (1-n2)*Fd(xpp(i),z2(j),ygg(k),tt+1))…
))+…
(1-b)*( …
m2*(…
p3(y1(j),k)*(n1*Fd(xp(i),zg(j),y1(k),tt+1) + (1-n1)*Fd(xpp(i) ,zgg(j),y1(k),tt+1))+ …
(1-p3(y1(j),k))*(n2*Fd(xp(i),z(j),yp(k),tt+1) + (1-n2)*Fd(xpp(i) ,z(j),ypp(k),tt+1)))+ …
(1-m2)*(p4(y2(j),k)*(n1*Fd(xp(i),zg(j),y2(k),tt+1) + (1-n1)*Fd(xpp(i),zgg(j),y2(k),tt+1))+…
(1-p4(y2(j),k))*(n2*Fd(xp(i),z(j),yd(k),tt+1) + (1-n2)*Fd(xpp(i),z(j),ydd(k),tt+1))));
Fdbb(i,j,k,tt)= p5(j,k)*( …
n1*Fdb(xd(i),zg(j),y(k),tt+1) + (1-n1)*Fdb(xdd(i),zgg(j),y(k),tt+1) …
)+…
(1-p5(j,k))*( …
n2*Fdb(xd(i),z(j),yg(k),tt+1) + (1-n2)*Fdb(xdd(i),z(j),ygg(k),tt+1)) …
;
%optimal decision and fitness
if Fdd(i,j,k,tt)>Fdbb(i,j,k,tt)
opt(i,j,k,tt)=1;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
elseif Fdd(i,j,k,tt)<Fdbb(i,j,k,tt)
opt(i,j,k,tt)=2;
Ft(i,j,k,tt)=Fdbb(i,j,k,tt);
elseif Fdd(i,j,k,tt)==Fdbb(i,j,k,tt)
opt(i,j,k,tt)=3;
Ft(i,j,k,tt)=Fdd(i,j,k,tt);
end
end
end
end
end
I would like to add in a forgetting rate so that it looks more like this:
l=0.95;
zp=l*(z1+1); %dem went to patch 1 and found food; obs went to patch 1 and found food
zp(zp>cap)=cap;
zpp=l*(z1-1); %dem went to patch1 and found food; obs went to patch 1 and didn’t find food
zpp(zpp<1)=1;
zd=l*(z2+1); %dem went to patch1 and didn’t find food; obs went to patch 1 and found food
zd(zd>cap)=cap;
zdd=l*(z2-1); %dem went to patch 1 and didn’t find food; obs went to patch 1 and didn’t find food
zdd(zdd<1)=1;
zg=l*(z+1); %obs went to patch 1 and found food
zg(zg>cap)=cap;
zgg=l*(z-1); %obs went to patch 1 and didn’t find food
zgg(zgg<1)=1;
%this would be added to the y’s as well
How do I edit the fitness equation to add in linear interpolation?
note that Fdd is a 4-D matrix, because it has a physical state (x), two infomational states (z and y), and then time (t)
most of the interpolation I see modifies 1-D matrices fitness equation, nonlinear, interpolation MATLAB Answers — New Questions
Adding Legend of Data Categories
I am trying to plot a single-line graph (alongside moving average and baseline) that is divided into multiple data categories mentioned in group_names. My last struggle is to add legend to the graph. Could anyone please help me how I could correctly add all category names from "group_names" with their corresponding color from "colors" into the legend ? The script includes my attempt of adding legend the way I have successfully done it before, however it does not work here.
Any help will be greatly appreciated.
I will post my full plotting script below to provide the idea of how my code works:
baseline_L = 885.63;
y1_L = [0,99,993,937];
… % unnecessary to post here, only 88 other 4-value vectors
y90_L = [2281,1364,0,0];
% GRAPH PLOTTING
y_values = [y1_L; y2_L; y3_L; y4_L; y5_L; y6_L; y7_L; y8_L; y9_L;…
y10_L; y11_L; y12_L; y13_L; y14_L; y15_L; y16_L; y17_L; y18_L; y19_L;…
y20_L; y21_L; y22_L; y23_L; y24_L; y25_L; y26_L; y27_L; y28_L; y29_L;…
y30_L; y31_L; y32_L; y33_L; y34_L; y35_L; y36_L; y37_L; y38_L; y39_L;…
y40_L; y41_L; y42_L; y43_L; y44_L; y45_L; y46_L; y47_L; y48_L; y49_L;…
y50_L; y51_L; y52_L; y53_L; y54_L; y55_L; y56_L; y57_L; y58_L; y59_L;…
y60_L; y61_L; y62_L; y63_L; y64_L; y65_L; y66_L; y67_L; y68_L; y69_L;…
y70_L; y71_L; y72_L; y73_L; y74_L; y75_L; y76_L; y77_L; y78_L; y79_L;…
y80_L; y81_L; y82_L; y83_L; y84_L; y85_L; y86_L; y87_L; y88_L; y89_L;…
y90];
[N,M] = size(y_values);
% GRAPH PLOTTING
colors = {"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE",…
"#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’};
% Define group names for legend
group_names = {‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘DCZ Pump’,’DCZ Pump’, ‘DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,…
‘Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,…
‘No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’};
% Plotting
figure(3);
hold on;
% Plot baseline
plot([0.5, N+0.5], [baseline, baseline], ‘k’, ‘LineWidth’, 2); % Black line with thicker width
h(N+1,1) = plot(NaN,NaN,’k’,’LineWidth’,2); % Dummy line for baseline in legend
% Calculate the mean for each date
mean_values = mean(y_values, 2);
% A moving average with a window size of 5
smooth_mean_values = movmean(mean_values, 5);
% Plot the smooth line
plot(1:N, smooth_mean_values, ‘LineWidth’, 2, ‘Color’, ‘b’);
h(N+2,1) = plot(NaN,NaN,’b’,’LineWidth’,2); % Dummy line for moving average in legend
x_new=0.75:0.25:N+0.5;
y_new=reshape(y_values’,[],1);
new_colors=repmat(colors,4,1);
new_colors=reshape(new_colors,[],1);
for i=1:359
plot([x_new(i),x_new(i+1)],[y_new(i),y_new(i+1)],’Color’,new_colors{i},’Marker’,’o’,’LineStyle’,’-‘,’MarkerFaceColor’,new_colors{i});
end
xticks(1:N); % Placing x-axis ticks for every value
xticklabels({‘13.12’, ‘14.12.’, ‘15.12.’, ‘16.12.’, ‘17.12.’, ‘18.12.’, ‘19.12.’,…
‘20.12.’,’21.12.’,’22.12.’,’23.12.’,’24.12.’,’25.12.’,’26.12.’,…
‘27.12.’,’28.12.’,’29.12.’,’30.12.’,’31.12.’, …
‘1.1.’,’2.1.’,’3.1.’,’4.1.’,’5.1.’,’6.1.’,’7.1.’,…
‘8.1.’,’9.1.’,’10.1.’,’11.1.’,’12.1.’,’13.1.’,’14.1.’,…
‘15.1.’,’16.1.’,’17.1.’,’18.1.’,’19.1.’,’20.1.’,’21.1.’,…
‘22.1.’,’23.1.’,’24.1.’,’25.1.’,’26.1.’,’27.1.’,’28.1.’,…
‘29.1.’,’30.1.’,’31.1.’,…
‘1.2.’,’2.2.’,’3.2.’,’4.2.’,’5.2.’,’6.2.’,’7.2.’,…
‘8.2.’,’9.2.’,’10.2.’,’11.2.’,’12.2.’,’13.2.’,’14.2.’,…
‘15.2.’,’16.2.’,’17.2.’,’18.2.’,’19.2.’,’20.2.’,’21.2.’,…
‘22.2.’,’23.2.’,’24.2.’,’25.2.’,’26.2.’,’27.2.’,’28.2.’,…
‘29.2.’…
‘1.3.’,’2.3.’,’3.3.’,’4.3.’,’5.3.’,’6.3.’,’7.3.’,…
‘8.3.’,’9.3.’,’10.3.’,’11.3.’, ‘Baseline’, ‘Moving Average’});
% Add legend
group_names{end+1} = ‘Baseline’; % Add baseline to the legend
group_names{end+1} = ‘Moving Average’; % Add moving average to the legend
[ugn,idx] = unique(group_names,’stable’);
legend(h(idx,1),ugn, ‘Location’, ‘northwest’); % from each group in the legend
% Add title and labels
title(‘IED Rate During Osmotic Pump and Injection Drug Administration of SK000918’, ‘FontSize’, 19);
xlabel(‘Date’, ‘FontSize’, 16);
ylabel(‘6-hour IED Rate’, ‘FontSize’, 16);
hold off;I am trying to plot a single-line graph (alongside moving average and baseline) that is divided into multiple data categories mentioned in group_names. My last struggle is to add legend to the graph. Could anyone please help me how I could correctly add all category names from "group_names" with their corresponding color from "colors" into the legend ? The script includes my attempt of adding legend the way I have successfully done it before, however it does not work here.
Any help will be greatly appreciated.
I will post my full plotting script below to provide the idea of how my code works:
baseline_L = 885.63;
y1_L = [0,99,993,937];
… % unnecessary to post here, only 88 other 4-value vectors
y90_L = [2281,1364,0,0];
% GRAPH PLOTTING
y_values = [y1_L; y2_L; y3_L; y4_L; y5_L; y6_L; y7_L; y8_L; y9_L;…
y10_L; y11_L; y12_L; y13_L; y14_L; y15_L; y16_L; y17_L; y18_L; y19_L;…
y20_L; y21_L; y22_L; y23_L; y24_L; y25_L; y26_L; y27_L; y28_L; y29_L;…
y30_L; y31_L; y32_L; y33_L; y34_L; y35_L; y36_L; y37_L; y38_L; y39_L;…
y40_L; y41_L; y42_L; y43_L; y44_L; y45_L; y46_L; y47_L; y48_L; y49_L;…
y50_L; y51_L; y52_L; y53_L; y54_L; y55_L; y56_L; y57_L; y58_L; y59_L;…
y60_L; y61_L; y62_L; y63_L; y64_L; y65_L; y66_L; y67_L; y68_L; y69_L;…
y70_L; y71_L; y72_L; y73_L; y74_L; y75_L; y76_L; y77_L; y78_L; y79_L;…
y80_L; y81_L; y82_L; y83_L; y84_L; y85_L; y86_L; y87_L; y88_L; y89_L;…
y90];
[N,M] = size(y_values);
% GRAPH PLOTTING
colors = {"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE",…
"#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’};
% Define group names for legend
group_names = {‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘DCZ Pump’,’DCZ Pump’, ‘DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,…
‘Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,…
‘No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’};
% Plotting
figure(3);
hold on;
% Plot baseline
plot([0.5, N+0.5], [baseline, baseline], ‘k’, ‘LineWidth’, 2); % Black line with thicker width
h(N+1,1) = plot(NaN,NaN,’k’,’LineWidth’,2); % Dummy line for baseline in legend
% Calculate the mean for each date
mean_values = mean(y_values, 2);
% A moving average with a window size of 5
smooth_mean_values = movmean(mean_values, 5);
% Plot the smooth line
plot(1:N, smooth_mean_values, ‘LineWidth’, 2, ‘Color’, ‘b’);
h(N+2,1) = plot(NaN,NaN,’b’,’LineWidth’,2); % Dummy line for moving average in legend
x_new=0.75:0.25:N+0.5;
y_new=reshape(y_values’,[],1);
new_colors=repmat(colors,4,1);
new_colors=reshape(new_colors,[],1);
for i=1:359
plot([x_new(i),x_new(i+1)],[y_new(i),y_new(i+1)],’Color’,new_colors{i},’Marker’,’o’,’LineStyle’,’-‘,’MarkerFaceColor’,new_colors{i});
end
xticks(1:N); % Placing x-axis ticks for every value
xticklabels({‘13.12’, ‘14.12.’, ‘15.12.’, ‘16.12.’, ‘17.12.’, ‘18.12.’, ‘19.12.’,…
‘20.12.’,’21.12.’,’22.12.’,’23.12.’,’24.12.’,’25.12.’,’26.12.’,…
‘27.12.’,’28.12.’,’29.12.’,’30.12.’,’31.12.’, …
‘1.1.’,’2.1.’,’3.1.’,’4.1.’,’5.1.’,’6.1.’,’7.1.’,…
‘8.1.’,’9.1.’,’10.1.’,’11.1.’,’12.1.’,’13.1.’,’14.1.’,…
‘15.1.’,’16.1.’,’17.1.’,’18.1.’,’19.1.’,’20.1.’,’21.1.’,…
‘22.1.’,’23.1.’,’24.1.’,’25.1.’,’26.1.’,’27.1.’,’28.1.’,…
‘29.1.’,’30.1.’,’31.1.’,…
‘1.2.’,’2.2.’,’3.2.’,’4.2.’,’5.2.’,’6.2.’,’7.2.’,…
‘8.2.’,’9.2.’,’10.2.’,’11.2.’,’12.2.’,’13.2.’,’14.2.’,…
‘15.2.’,’16.2.’,’17.2.’,’18.2.’,’19.2.’,’20.2.’,’21.2.’,…
‘22.2.’,’23.2.’,’24.2.’,’25.2.’,’26.2.’,’27.2.’,’28.2.’,…
‘29.2.’…
‘1.3.’,’2.3.’,’3.3.’,’4.3.’,’5.3.’,’6.3.’,’7.3.’,…
‘8.3.’,’9.3.’,’10.3.’,’11.3.’, ‘Baseline’, ‘Moving Average’});
% Add legend
group_names{end+1} = ‘Baseline’; % Add baseline to the legend
group_names{end+1} = ‘Moving Average’; % Add moving average to the legend
[ugn,idx] = unique(group_names,’stable’);
legend(h(idx,1),ugn, ‘Location’, ‘northwest’); % from each group in the legend
% Add title and labels
title(‘IED Rate During Osmotic Pump and Injection Drug Administration of SK000918’, ‘FontSize’, 19);
xlabel(‘Date’, ‘FontSize’, 16);
ylabel(‘6-hour IED Rate’, ‘FontSize’, 16);
hold off; I am trying to plot a single-line graph (alongside moving average and baseline) that is divided into multiple data categories mentioned in group_names. My last struggle is to add legend to the graph. Could anyone please help me how I could correctly add all category names from "group_names" with their corresponding color from "colors" into the legend ? The script includes my attempt of adding legend the way I have successfully done it before, however it does not work here.
Any help will be greatly appreciated.
I will post my full plotting script below to provide the idea of how my code works:
baseline_L = 885.63;
y1_L = [0,99,993,937];
… % unnecessary to post here, only 88 other 4-value vectors
y90_L = [2281,1364,0,0];
% GRAPH PLOTTING
y_values = [y1_L; y2_L; y3_L; y4_L; y5_L; y6_L; y7_L; y8_L; y9_L;…
y10_L; y11_L; y12_L; y13_L; y14_L; y15_L; y16_L; y17_L; y18_L; y19_L;…
y20_L; y21_L; y22_L; y23_L; y24_L; y25_L; y26_L; y27_L; y28_L; y29_L;…
y30_L; y31_L; y32_L; y33_L; y34_L; y35_L; y36_L; y37_L; y38_L; y39_L;…
y40_L; y41_L; y42_L; y43_L; y44_L; y45_L; y46_L; y47_L; y48_L; y49_L;…
y50_L; y51_L; y52_L; y53_L; y54_L; y55_L; y56_L; y57_L; y58_L; y59_L;…
y60_L; y61_L; y62_L; y63_L; y64_L; y65_L; y66_L; y67_L; y68_L; y69_L;…
y70_L; y71_L; y72_L; y73_L; y74_L; y75_L; y76_L; y77_L; y78_L; y79_L;…
y80_L; y81_L; y82_L; y83_L; y84_L; y85_L; y86_L; y87_L; y88_L; y89_L;…
y90];
[N,M] = size(y_values);
% GRAPH PLOTTING
colors = {"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
"#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE", "#4DBEEE",…
"#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120", "#EDB120",…
"#D95319", "#D95319", "#D95319", "#D95319", "#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’, ‘y’, ‘y’, ‘y’, ‘y’,…
"#D95319", "#D95319",…
"#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF", "#ED33FF",…
"#D95319", "#D95319",…
‘y’};
% Define group names for legend
group_names = {‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’, ‘No Drug Administration’,…
‘DCZ Pump’,’DCZ Pump’, ‘DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,’DCZ Pump’,…
‘Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,’Saline Pump’,…
‘No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,’DCZ Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,’Saline Injection’,…
‘No Drug Administration’,’No Drug Administration’,…
‘DCZ Injection’};
% Plotting
figure(3);
hold on;
% Plot baseline
plot([0.5, N+0.5], [baseline, baseline], ‘k’, ‘LineWidth’, 2); % Black line with thicker width
h(N+1,1) = plot(NaN,NaN,’k’,’LineWidth’,2); % Dummy line for baseline in legend
% Calculate the mean for each date
mean_values = mean(y_values, 2);
% A moving average with a window size of 5
smooth_mean_values = movmean(mean_values, 5);
% Plot the smooth line
plot(1:N, smooth_mean_values, ‘LineWidth’, 2, ‘Color’, ‘b’);
h(N+2,1) = plot(NaN,NaN,’b’,’LineWidth’,2); % Dummy line for moving average in legend
x_new=0.75:0.25:N+0.5;
y_new=reshape(y_values’,[],1);
new_colors=repmat(colors,4,1);
new_colors=reshape(new_colors,[],1);
for i=1:359
plot([x_new(i),x_new(i+1)],[y_new(i),y_new(i+1)],’Color’,new_colors{i},’Marker’,’o’,’LineStyle’,’-‘,’MarkerFaceColor’,new_colors{i});
end
xticks(1:N); % Placing x-axis ticks for every value
xticklabels({‘13.12’, ‘14.12.’, ‘15.12.’, ‘16.12.’, ‘17.12.’, ‘18.12.’, ‘19.12.’,…
‘20.12.’,’21.12.’,’22.12.’,’23.12.’,’24.12.’,’25.12.’,’26.12.’,…
‘27.12.’,’28.12.’,’29.12.’,’30.12.’,’31.12.’, …
‘1.1.’,’2.1.’,’3.1.’,’4.1.’,’5.1.’,’6.1.’,’7.1.’,…
‘8.1.’,’9.1.’,’10.1.’,’11.1.’,’12.1.’,’13.1.’,’14.1.’,…
‘15.1.’,’16.1.’,’17.1.’,’18.1.’,’19.1.’,’20.1.’,’21.1.’,…
‘22.1.’,’23.1.’,’24.1.’,’25.1.’,’26.1.’,’27.1.’,’28.1.’,…
‘29.1.’,’30.1.’,’31.1.’,…
‘1.2.’,’2.2.’,’3.2.’,’4.2.’,’5.2.’,’6.2.’,’7.2.’,…
‘8.2.’,’9.2.’,’10.2.’,’11.2.’,’12.2.’,’13.2.’,’14.2.’,…
‘15.2.’,’16.2.’,’17.2.’,’18.2.’,’19.2.’,’20.2.’,’21.2.’,…
‘22.2.’,’23.2.’,’24.2.’,’25.2.’,’26.2.’,’27.2.’,’28.2.’,…
‘29.2.’…
‘1.3.’,’2.3.’,’3.3.’,’4.3.’,’5.3.’,’6.3.’,’7.3.’,…
‘8.3.’,’9.3.’,’10.3.’,’11.3.’, ‘Baseline’, ‘Moving Average’});
% Add legend
group_names{end+1} = ‘Baseline’; % Add baseline to the legend
group_names{end+1} = ‘Moving Average’; % Add moving average to the legend
[ugn,idx] = unique(group_names,’stable’);
legend(h(idx,1),ugn, ‘Location’, ‘northwest’); % from each group in the legend
% Add title and labels
title(‘IED Rate During Osmotic Pump and Injection Drug Administration of SK000918’, ‘FontSize’, 19);
xlabel(‘Date’, ‘FontSize’, 16);
ylabel(‘6-hour IED Rate’, ‘FontSize’, 16);
hold off; adding legend, data categories, plotting MATLAB Answers — New Questions
Has anyone used a speedgoat with sensors and actuators to test a SIMULINK-designed flight controller as a RCP/HIL?
I am currently trying to develop an Iron bird testbed for an UAV to test its harware components and evaluate the real-time capabilities of the designed flight controllers using a speedgoat. I was thinking of starting with a rate gyro sensor (for pitch rate feedback), a servo (acting as an elevator), and testing a simple pitch rate controller feedback using the speedgoat to communicate with harware and SIMULINK and test the designed closed loop pitch controller. I was wondering if anyone has done anything similar- designing control algorithms in Simulink and leveraging a Speedgoat target computer as a prototype for the final controller, and/or test hardware components (Rapid Control Prototyping- RCP)? I’m eager to know what has been done and how 🙂
Thanks,
-JI am currently trying to develop an Iron bird testbed for an UAV to test its harware components and evaluate the real-time capabilities of the designed flight controllers using a speedgoat. I was thinking of starting with a rate gyro sensor (for pitch rate feedback), a servo (acting as an elevator), and testing a simple pitch rate controller feedback using the speedgoat to communicate with harware and SIMULINK and test the designed closed loop pitch controller. I was wondering if anyone has done anything similar- designing control algorithms in Simulink and leveraging a Speedgoat target computer as a prototype for the final controller, and/or test hardware components (Rapid Control Prototyping- RCP)? I’m eager to know what has been done and how 🙂
Thanks,
-J I am currently trying to develop an Iron bird testbed for an UAV to test its harware components and evaluate the real-time capabilities of the designed flight controllers using a speedgoat. I was thinking of starting with a rate gyro sensor (for pitch rate feedback), a servo (acting as an elevator), and testing a simple pitch rate controller feedback using the speedgoat to communicate with harware and SIMULINK and test the designed closed loop pitch controller. I was wondering if anyone has done anything similar- designing control algorithms in Simulink and leveraging a Speedgoat target computer as a prototype for the final controller, and/or test hardware components (Rapid Control Prototyping- RCP)? I’m eager to know what has been done and how 🙂
Thanks,
-J simulink, speedgoat, real-time, matlab, embedded coder, hardware-in-the-loop, communication, matlab coder MATLAB Answers — New Questions
How to create a LPV model from a given vector of operating points?
I have a 2 parameter LPV system that I wish to design a PID for it later and I also have the operating points so I don’t need to use the linearize function, as most examples do. I don’t understand well how the lpvss function works, how can I input my operating points vectors to it? How do I use it to create a system for each point?
Worst case scenario I think I can do it manually for each system, but it would be very nice if I can do it in a more efficient and compact way.
% Parameters
X_u = 0;
m = 5037.7;
V_ops = [20 22 24 26 28 30]* 1.852/3.6;
X_uu_ops = [33.5345 27.7066 23.6158 20.9720 19.3457 18.2671];
% Equilibrium points
operatingPoints = [V_ops; X_uu_ops];
x0 = operatingPoints(1,1);
X_uu = operatingPoints(2,1)
u0 = X_u*x0 + X_uu*x0^2 % Propeller thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0)
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
sys_ol = ss(A,B,C,D);
lpvsys = lpvss([‘v’ ‘X_uu’],@PlantLPV)
function [A,B,C,D,E,dx0,x0,u0,y0,Delays] = PlantLPV(~,v,X_uu)
X_u = 0;
m = 5037;
A = -(X_u/m + 2*X_uu/m*v);
B = 1/m;
C = 1;
D = 0;
E = [];
u0 = X_u*v + X_uu*v^2;
dx0 = [];
x0 = v;
y0 = v;
Delays = [];
endI have a 2 parameter LPV system that I wish to design a PID for it later and I also have the operating points so I don’t need to use the linearize function, as most examples do. I don’t understand well how the lpvss function works, how can I input my operating points vectors to it? How do I use it to create a system for each point?
Worst case scenario I think I can do it manually for each system, but it would be very nice if I can do it in a more efficient and compact way.
% Parameters
X_u = 0;
m = 5037.7;
V_ops = [20 22 24 26 28 30]* 1.852/3.6;
X_uu_ops = [33.5345 27.7066 23.6158 20.9720 19.3457 18.2671];
% Equilibrium points
operatingPoints = [V_ops; X_uu_ops];
x0 = operatingPoints(1,1);
X_uu = operatingPoints(2,1)
u0 = X_u*x0 + X_uu*x0^2 % Propeller thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0)
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
sys_ol = ss(A,B,C,D);
lpvsys = lpvss([‘v’ ‘X_uu’],@PlantLPV)
function [A,B,C,D,E,dx0,x0,u0,y0,Delays] = PlantLPV(~,v,X_uu)
X_u = 0;
m = 5037;
A = -(X_u/m + 2*X_uu/m*v);
B = 1/m;
C = 1;
D = 0;
E = [];
u0 = X_u*v + X_uu*v^2;
dx0 = [];
x0 = v;
y0 = v;
Delays = [];
end I have a 2 parameter LPV system that I wish to design a PID for it later and I also have the operating points so I don’t need to use the linearize function, as most examples do. I don’t understand well how the lpvss function works, how can I input my operating points vectors to it? How do I use it to create a system for each point?
Worst case scenario I think I can do it manually for each system, but it would be very nice if I can do it in a more efficient and compact way.
% Parameters
X_u = 0;
m = 5037.7;
V_ops = [20 22 24 26 28 30]* 1.852/3.6;
X_uu_ops = [33.5345 27.7066 23.6158 20.9720 19.3457 18.2671];
% Equilibrium points
operatingPoints = [V_ops; X_uu_ops];
x0 = operatingPoints(1,1);
X_uu = operatingPoints(2,1)
u0 = X_u*x0 + X_uu*x0^2 % Propeller thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0)
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
sys_ol = ss(A,B,C,D);
lpvsys = lpvss([‘v’ ‘X_uu’],@PlantLPV)
function [A,B,C,D,E,dx0,x0,u0,y0,Delays] = PlantLPV(~,v,X_uu)
X_u = 0;
m = 5037;
A = -(X_u/m + 2*X_uu/m*v);
B = 1/m;
C = 1;
D = 0;
E = [];
u0 = X_u*v + X_uu*v^2;
dx0 = [];
x0 = v;
y0 = v;
Delays = [];
end lpvss, gain scheduling MATLAB Answers — New Questions
(Gui) app designer in matlap
hello everyone, i have a problem, i want to redo the job of calculating the source activity at time t when the “calculate” button is pressed. History in time The application calculates from button press (t0) until time t, on the app designer in matlaphello everyone, i have a problem, i want to redo the job of calculating the source activity at time t when the “calculate” button is pressed. History in time The application calculates from button press (t0) until time t, on the app designer in matlap hello everyone, i have a problem, i want to redo the job of calculating the source activity at time t when the “calculate” button is pressed. History in time The application calculates from button press (t0) until time t, on the app designer in matlap (gui) app designer in matlap MATLAB Answers — New Questions
how to not violate from trnasparency in parloop? (a good replacement for “which” or “exist”)
Hello!
inside the body of my parloop, I have to evaluate the existance of sth in my workspace then based on that, run a piece of code,
of course this is not working:
if exist(‘NHP_SoloB’)
Actor_B= string(report_struct.unique_lists.B_Name);
else
Actor_A = string(report_struct.unique_lists.A_Name);
end
%
%
loadedDATA = array2table(report_struct.data,’VariableNames’,report_struct.header);
if exist(‘NHP_SoloB’)
Rewarded_Aborted = report_struct.unique_lists.B_OutcomeENUM(loadedDATA.B_OutcomeENUM_idx);
else
Rewarded_Aborted = report_struct.unique_lists.A_OutcomeENUM(loadedDATA.A_OutcomeENUM_idx);
end
exist or which can not be used here bc they violates with transparency rules , do you have any suggestion to be consistent with transparency of the workspace?Hello!
inside the body of my parloop, I have to evaluate the existance of sth in my workspace then based on that, run a piece of code,
of course this is not working:
if exist(‘NHP_SoloB’)
Actor_B= string(report_struct.unique_lists.B_Name);
else
Actor_A = string(report_struct.unique_lists.A_Name);
end
%
%
loadedDATA = array2table(report_struct.data,’VariableNames’,report_struct.header);
if exist(‘NHP_SoloB’)
Rewarded_Aborted = report_struct.unique_lists.B_OutcomeENUM(loadedDATA.B_OutcomeENUM_idx);
else
Rewarded_Aborted = report_struct.unique_lists.A_OutcomeENUM(loadedDATA.A_OutcomeENUM_idx);
end
exist or which can not be used here bc they violates with transparency rules , do you have any suggestion to be consistent with transparency of the workspace? Hello!
inside the body of my parloop, I have to evaluate the existance of sth in my workspace then based on that, run a piece of code,
of course this is not working:
if exist(‘NHP_SoloB’)
Actor_B= string(report_struct.unique_lists.B_Name);
else
Actor_A = string(report_struct.unique_lists.A_Name);
end
%
%
loadedDATA = array2table(report_struct.data,’VariableNames’,report_struct.header);
if exist(‘NHP_SoloB’)
Rewarded_Aborted = report_struct.unique_lists.B_OutcomeENUM(loadedDATA.B_OutcomeENUM_idx);
else
Rewarded_Aborted = report_struct.unique_lists.A_OutcomeENUM(loadedDATA.A_OutcomeENUM_idx);
end
exist or which can not be used here bc they violates with transparency rules , do you have any suggestion to be consistent with transparency of the workspace? parloop, optimization, transparency MATLAB Answers — New Questions
How to have different line styles and markers in one plot?
This is my code. For now, it is only o- for all six configurations. i want each to have different markers and line styles.
% Define alpha values
alpha_values = [0, 0.25, 0.5, 0.75, 1];
% Define gamma values for each alpha
gamma_values = [
1, 0.943, 0.577, 0.941, 0.851, 0.988; % Alpha = 0
0.971, 0.9146, 0.6267, 0.9, 0.886, 0.977; % Alpha = 0.25
0.941, 0.8958, 0.6778, 0.8593, 0.9233, 0.9676; % Alpha = 0.5
0.912, 0.87, 0.728, 0.818, 0.958 0.9575; % Alpha = 0.75
0.8826, 0.848, 0.7786, 0.777, 0.9959,0.947; % Alpha = 1
];
% Define gamma values for each alpha
gamma_values_kron = [
0.811, 0.75, 0.929, 0.929, 0.75, 1; % Alpha = 0
0.838, 0.808, 0.941, 0.927, 0.759, 0.988; % Alpha = 0.25
0.865, 0.864, 0.951, 0.928, 0.771, 0.977; % Alpha = 0.5
0.896, 0.927, 0.968, 0.926, 0.780 0.965; % Alpha = 0.75
0.926, 0.987, 0.981, 0.926, 0.791,0.954; % Alpha = 1
];
% Plot the values
figure;
plot(alpha_values, gamma_values, ‘o-‘, ‘LineWidth’, 1.5);
xlabel(‘alpha’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
ylabel(‘gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
set(gca, ‘FontSize’, 12, ‘FontWeight’, ‘bold’);
title(‘alpha vs. gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
legend(‘Gold-Chaotic’, ‘Kasami-Chaotic’, ‘Gold-Kasami’, ‘Barker-Gold’, ‘Barker-Chaotic’, ‘Barker-Kasami’, ‘Location’, ‘Best’);
grid on;This is my code. For now, it is only o- for all six configurations. i want each to have different markers and line styles.
% Define alpha values
alpha_values = [0, 0.25, 0.5, 0.75, 1];
% Define gamma values for each alpha
gamma_values = [
1, 0.943, 0.577, 0.941, 0.851, 0.988; % Alpha = 0
0.971, 0.9146, 0.6267, 0.9, 0.886, 0.977; % Alpha = 0.25
0.941, 0.8958, 0.6778, 0.8593, 0.9233, 0.9676; % Alpha = 0.5
0.912, 0.87, 0.728, 0.818, 0.958 0.9575; % Alpha = 0.75
0.8826, 0.848, 0.7786, 0.777, 0.9959,0.947; % Alpha = 1
];
% Define gamma values for each alpha
gamma_values_kron = [
0.811, 0.75, 0.929, 0.929, 0.75, 1; % Alpha = 0
0.838, 0.808, 0.941, 0.927, 0.759, 0.988; % Alpha = 0.25
0.865, 0.864, 0.951, 0.928, 0.771, 0.977; % Alpha = 0.5
0.896, 0.927, 0.968, 0.926, 0.780 0.965; % Alpha = 0.75
0.926, 0.987, 0.981, 0.926, 0.791,0.954; % Alpha = 1
];
% Plot the values
figure;
plot(alpha_values, gamma_values, ‘o-‘, ‘LineWidth’, 1.5);
xlabel(‘alpha’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
ylabel(‘gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
set(gca, ‘FontSize’, 12, ‘FontWeight’, ‘bold’);
title(‘alpha vs. gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
legend(‘Gold-Chaotic’, ‘Kasami-Chaotic’, ‘Gold-Kasami’, ‘Barker-Gold’, ‘Barker-Chaotic’, ‘Barker-Kasami’, ‘Location’, ‘Best’);
grid on; This is my code. For now, it is only o- for all six configurations. i want each to have different markers and line styles.
% Define alpha values
alpha_values = [0, 0.25, 0.5, 0.75, 1];
% Define gamma values for each alpha
gamma_values = [
1, 0.943, 0.577, 0.941, 0.851, 0.988; % Alpha = 0
0.971, 0.9146, 0.6267, 0.9, 0.886, 0.977; % Alpha = 0.25
0.941, 0.8958, 0.6778, 0.8593, 0.9233, 0.9676; % Alpha = 0.5
0.912, 0.87, 0.728, 0.818, 0.958 0.9575; % Alpha = 0.75
0.8826, 0.848, 0.7786, 0.777, 0.9959,0.947; % Alpha = 1
];
% Define gamma values for each alpha
gamma_values_kron = [
0.811, 0.75, 0.929, 0.929, 0.75, 1; % Alpha = 0
0.838, 0.808, 0.941, 0.927, 0.759, 0.988; % Alpha = 0.25
0.865, 0.864, 0.951, 0.928, 0.771, 0.977; % Alpha = 0.5
0.896, 0.927, 0.968, 0.926, 0.780 0.965; % Alpha = 0.75
0.926, 0.987, 0.981, 0.926, 0.791,0.954; % Alpha = 1
];
% Plot the values
figure;
plot(alpha_values, gamma_values, ‘o-‘, ‘LineWidth’, 1.5);
xlabel(‘alpha’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
ylabel(‘gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
set(gca, ‘FontSize’, 12, ‘FontWeight’, ‘bold’);
title(‘alpha vs. gamma’,’FontSize’, 16, ‘FontWeight’, ‘bold’);
legend(‘Gold-Chaotic’, ‘Kasami-Chaotic’, ‘Gold-Kasami’, ‘Barker-Gold’, ‘Barker-Chaotic’, ‘Barker-Kasami’, ‘Location’, ‘Best’);
grid on; matlab, subplot, plot MATLAB Answers — New Questions
Simulink Codegen for multiple models
Hi
I’m trying to generate C code from multiple models and run them using my own C program.
Problem is all the models include definitions for specific functions, for instance
look1_binlxpw. and C++ linker doesn’t like multiple definitions. Is there anyway to force it include these common functions in another translation unit (another .c file).
I’ve seen help pages about using model reference hierarchies for doing this, but unfortunately that doesn’t apply to my current use case.
thanksHi
I’m trying to generate C code from multiple models and run them using my own C program.
Problem is all the models include definitions for specific functions, for instance
look1_binlxpw. and C++ linker doesn’t like multiple definitions. Is there anyway to force it include these common functions in another translation unit (another .c file).
I’ve seen help pages about using model reference hierarchies for doing this, but unfortunately that doesn’t apply to my current use case.
thanks Hi
I’m trying to generate C code from multiple models and run them using my own C program.
Problem is all the models include definitions for specific functions, for instance
look1_binlxpw. and C++ linker doesn’t like multiple definitions. Is there anyway to force it include these common functions in another translation unit (another .c file).
I’ve seen help pages about using model reference hierarchies for doing this, but unfortunately that doesn’t apply to my current use case.
thanks simulink, code generation, multiple models MATLAB Answers — New Questions
Implement ros timers in stateflow
Problem
I want to create a stateflow chart that triggers a controller (enabled/function-call subsystem) every 100ms. However, if certain conditions are met during the intermediate time between controller runs, the controller must be called and afterwards, the timer must be resetted. (Reset the controller)
I tried to make an simplified version of the above, however it does not work as expected.
Also, the version is R2022b, but i couldn’t put it when i sumbitted the question.
Current program
Where the stateflow chart (Controller Governor) is the following:
What i get is (vs what i expect to get is the following):
Background and general goal
I am trying to simulate an MPC controller (which i intent to port to ros) in simscape. The weights and setpoints of the MPC change depending on its current position in the workspace. I want to create "interrupting" logic that detects if i should change the weights of the MPC based on the current position.
In cpp the above could be achieved with that:
“`
ros::Timer timer = nh.createTimer(ros::Duration(0.1), run_controller);
while(ros::ok()){
resetting = check_reseting_conditions();
if (resetting==true){
timer.stop();
run_controller();
timer.start();
}
}
“`Problem
I want to create a stateflow chart that triggers a controller (enabled/function-call subsystem) every 100ms. However, if certain conditions are met during the intermediate time between controller runs, the controller must be called and afterwards, the timer must be resetted. (Reset the controller)
I tried to make an simplified version of the above, however it does not work as expected.
Also, the version is R2022b, but i couldn’t put it when i sumbitted the question.
Current program
Where the stateflow chart (Controller Governor) is the following:
What i get is (vs what i expect to get is the following):
Background and general goal
I am trying to simulate an MPC controller (which i intent to port to ros) in simscape. The weights and setpoints of the MPC change depending on its current position in the workspace. I want to create "interrupting" logic that detects if i should change the weights of the MPC based on the current position.
In cpp the above could be achieved with that:
“`
ros::Timer timer = nh.createTimer(ros::Duration(0.1), run_controller);
while(ros::ok()){
resetting = check_reseting_conditions();
if (resetting==true){
timer.stop();
run_controller();
timer.start();
}
}
“` Problem
I want to create a stateflow chart that triggers a controller (enabled/function-call subsystem) every 100ms. However, if certain conditions are met during the intermediate time between controller runs, the controller must be called and afterwards, the timer must be resetted. (Reset the controller)
I tried to make an simplified version of the above, however it does not work as expected.
Also, the version is R2022b, but i couldn’t put it when i sumbitted the question.
Current program
Where the stateflow chart (Controller Governor) is the following:
What i get is (vs what i expect to get is the following):
Background and general goal
I am trying to simulate an MPC controller (which i intent to port to ros) in simscape. The weights and setpoints of the MPC change depending on its current position in the workspace. I want to create "interrupting" logic that detects if i should change the weights of the MPC based on the current position.
In cpp the above could be achieved with that:
“`
ros::Timer timer = nh.createTimer(ros::Duration(0.1), run_controller);
while(ros::ok()){
resetting = check_reseting_conditions();
if (resetting==true){
timer.stop();
run_controller();
timer.start();
}
}
“` timer, stateflow, simulink, temporal logic MATLAB Answers — New Questions
GPU Coder error “Function ‘addDependentFile’ not supported for code generation.”
Hello,
I encounter the following error when using the GPU coder to convert a function and pre-trained-resnet model to a .mex file:
"Function ‘addDependentFile’ not supported for code generation."
I don’t know what causes it, and online search points to nothing. I use the GPU Coder app, but the same happens when I run from the command line. Bellow, you can see the a screenshot of the errors in the GPU Coder app. There you can also see the function I use.
The function is super basic and based on what I’ve seen in MATLAB tutorial this video. I’ve added the function as an attachment to test. As input, I use ones(224,224,3,’uint8′).
I have a Windows system and the CUDA toolkit v11.0 installed with driver 452.06. I also have cudnn v8.1.1.33 and Visual Studio 2019 (for the c++ compiler?) installed. Bellow you can see a screenshot of nvidia-smi and nvcc -V.
Can anyone please help me? Thank you in advance!
Cheers
Tim
GPU Coder app screenshot
nvidia-smi screenshot
nvcc -V screenshotHello,
I encounter the following error when using the GPU coder to convert a function and pre-trained-resnet model to a .mex file:
"Function ‘addDependentFile’ not supported for code generation."
I don’t know what causes it, and online search points to nothing. I use the GPU Coder app, but the same happens when I run from the command line. Bellow, you can see the a screenshot of the errors in the GPU Coder app. There you can also see the function I use.
The function is super basic and based on what I’ve seen in MATLAB tutorial this video. I’ve added the function as an attachment to test. As input, I use ones(224,224,3,’uint8′).
I have a Windows system and the CUDA toolkit v11.0 installed with driver 452.06. I also have cudnn v8.1.1.33 and Visual Studio 2019 (for the c++ compiler?) installed. Bellow you can see a screenshot of nvidia-smi and nvcc -V.
Can anyone please help me? Thank you in advance!
Cheers
Tim
GPU Coder app screenshot
nvidia-smi screenshot
nvcc -V screenshot Hello,
I encounter the following error when using the GPU coder to convert a function and pre-trained-resnet model to a .mex file:
"Function ‘addDependentFile’ not supported for code generation."
I don’t know what causes it, and online search points to nothing. I use the GPU Coder app, but the same happens when I run from the command line. Bellow, you can see the a screenshot of the errors in the GPU Coder app. There you can also see the function I use.
The function is super basic and based on what I’ve seen in MATLAB tutorial this video. I’ve added the function as an attachment to test. As input, I use ones(224,224,3,’uint8′).
I have a Windows system and the CUDA toolkit v11.0 installed with driver 452.06. I also have cudnn v8.1.1.33 and Visual Studio 2019 (for the c++ compiler?) installed. Bellow you can see a screenshot of nvidia-smi and nvcc -V.
Can anyone please help me? Thank you in advance!
Cheers
Tim
GPU Coder app screenshot
nvidia-smi screenshot
nvcc -V screenshot gpu, deep learning, gpu coder, mex, cuda MATLAB Answers — New Questions
This submission seems to have been previously rejected or deleted. Please contact the File Exchange admin if you wish to upload it again.
I tried to upload a deleted file, but the message comes:
"This submission seems to have been previously rejected or deleted. Please contact the File Exchange admin if you wish to upload it again."
My original file page is "https://www.mathworks.com/matlabcentral/fileexchange/161136-whatshow_phy_mod_otfs"
I do want to upload again and the file name is still "whatshow_phy_mod_otfs.mltbx". Is there any admin that could help me? Many thanks.I tried to upload a deleted file, but the message comes:
"This submission seems to have been previously rejected or deleted. Please contact the File Exchange admin if you wish to upload it again."
My original file page is "https://www.mathworks.com/matlabcentral/fileexchange/161136-whatshow_phy_mod_otfs"
I do want to upload again and the file name is still "whatshow_phy_mod_otfs.mltbx". Is there any admin that could help me? Many thanks. I tried to upload a deleted file, but the message comes:
"This submission seems to have been previously rejected or deleted. Please contact the File Exchange admin if you wish to upload it again."
My original file page is "https://www.mathworks.com/matlabcentral/fileexchange/161136-whatshow_phy_mod_otfs"
I do want to upload again and the file name is still "whatshow_phy_mod_otfs.mltbx". Is there any admin that could help me? Many thanks. file exchange admin MATLAB Answers — New Questions
Searching for Transferfunction between two functions
Hello,
the problem is as follows:
I have two functions (F1 and F2 both dependent on the time) from a data fit and I am searching for a transfer function (TF) that fulfills the following equation.
F2=F1*TF
TF should be given by an equation where two variables needs to be changed. The script has to change the variables to minimize the sum of squares errors between the original function F2 and the analytical result of F1*TF (which should be as close to F2 as possible).
R^2=(F2-F1*TF)^2 =!= min
I am open for any suggestions.
Thanks in advanceHello,
the problem is as follows:
I have two functions (F1 and F2 both dependent on the time) from a data fit and I am searching for a transfer function (TF) that fulfills the following equation.
F2=F1*TF
TF should be given by an equation where two variables needs to be changed. The script has to change the variables to minimize the sum of squares errors between the original function F2 and the analytical result of F1*TF (which should be as close to F2 as possible).
R^2=(F2-F1*TF)^2 =!= min
I am open for any suggestions.
Thanks in advance Hello,
the problem is as follows:
I have two functions (F1 and F2 both dependent on the time) from a data fit and I am searching for a transfer function (TF) that fulfills the following equation.
F2=F1*TF
TF should be given by an equation where two variables needs to be changed. The script has to change the variables to minimize the sum of squares errors between the original function F2 and the analytical result of F1*TF (which should be as close to F2 as possible).
R^2=(F2-F1*TF)^2 =!= min
I am open for any suggestions.
Thanks in advance transfer function MATLAB Answers — New Questions