Tag Archives: matlab
Compiling a single file for multiple Sfun
I want multiple sfun blocks to use a common C file in Simulink, but I get an error. Is this kind of usage possible ?I want multiple sfun blocks to use a common C file in Simulink, but I get an error. Is this kind of usage possible ? I want multiple sfun blocks to use a common C file in Simulink, but I get an error. Is this kind of usage possible ? simulink, embedded coder, mex compiler MATLAB Answers — New Questions
Error during training: Invalid training data. Y must be a vector of categorical responses.
am using single image as input for cnn for segmentation above error am getting please help me to resolveam using single image as input for cnn for segmentation above error am getting please help me to resolve am using single image as input for cnn for segmentation above error am getting please help me to resolve help me in this error MATLAB Answers — New Questions
Why am I unable to start the Network License Manager on Linux?
Why do I receive one of the following errors when I try to launch the Network License Manager on Linux?
./lmgrd: Command not found.
/lib64/ld-lsb-x86-64.so.3: bad ELF interpreter: No such file or directory
MLM: can’t initialize: Invalid license file syntax. (-2,40027) EXITING DUE TO SIGNAL 52 Exit reason 20
eval: 1: /var/tmp/lm_TMW.ld: not found
Waiting 300 secs for MATLAB vendor daemon to come up . . .
Type your interrupt character (usually CTRL-C) to quit.
Time = 3 secs : still waiting . . .
/usr/local/MATLAB/R2024a/etc/glnxa64/lmhostid: not found
Error: Your hostname matches the hostname on a SERVER line in
your license file but the lmhostid in that line does not.
Your local lmhostid(s) are:
Your hostname is: licserver1.support.mathworks.com
The SERVER line in question is:
———————————————–
SERVER licserver1.support.mathworks.com 001122DDEE99 27000
———————————————–
Please stop, fix the problem, and try again . . .Why do I receive one of the following errors when I try to launch the Network License Manager on Linux?
./lmgrd: Command not found.
/lib64/ld-lsb-x86-64.so.3: bad ELF interpreter: No such file or directory
MLM: can’t initialize: Invalid license file syntax. (-2,40027) EXITING DUE TO SIGNAL 52 Exit reason 20
eval: 1: /var/tmp/lm_TMW.ld: not found
Waiting 300 secs for MATLAB vendor daemon to come up . . .
Type your interrupt character (usually CTRL-C) to quit.
Time = 3 secs : still waiting . . .
/usr/local/MATLAB/R2024a/etc/glnxa64/lmhostid: not found
Error: Your hostname matches the hostname on a SERVER line in
your license file but the lmhostid in that line does not.
Your local lmhostid(s) are:
Your hostname is: licserver1.support.mathworks.com
The SERVER line in question is:
———————————————–
SERVER licserver1.support.mathworks.com 001122DDEE99 27000
———————————————–
Please stop, fix the problem, and try again . . . Why do I receive one of the following errors when I try to launch the Network License Manager on Linux?
./lmgrd: Command not found.
/lib64/ld-lsb-x86-64.so.3: bad ELF interpreter: No such file or directory
MLM: can’t initialize: Invalid license file syntax. (-2,40027) EXITING DUE TO SIGNAL 52 Exit reason 20
eval: 1: /var/tmp/lm_TMW.ld: not found
Waiting 300 secs for MATLAB vendor daemon to come up . . .
Type your interrupt character (usually CTRL-C) to quit.
Time = 3 secs : still waiting . . .
/usr/local/MATLAB/R2024a/etc/glnxa64/lmhostid: not found
Error: Your hostname matches the hostname on a SERVER line in
your license file but the lmhostid in that line does not.
Your local lmhostid(s) are:
Your hostname is: licserver1.support.mathworks.com
The SERVER line in question is:
———————————————–
SERVER licserver1.support.mathworks.com 001122DDEE99 27000
———————————————–
Please stop, fix the problem, and try again . . . MATLAB Answers — New Questions
Swarmchart maximum diplay for shapley?
I will draw a shapey model with Swarmchart. When I draw it, it shows a maximum of 10 predictors on the right axis. How can I increase it to 20?
Example;
swarmchart(explainer,’Class’,1)I will draw a shapey model with Swarmchart. When I draw it, it shows a maximum of 10 predictors on the right axis. How can I increase it to 20?
Example;
swarmchart(explainer,’Class’,1) I will draw a shapey model with Swarmchart. When I draw it, it shows a maximum of 10 predictors on the right axis. How can I increase it to 20?
Example;
swarmchart(explainer,’Class’,1) swarmchart, shapley MATLAB Answers — New Questions
I have a ECG signal along with a respiration signal, I need to filter it to separate the ECG and the Respiration signals. Also, extract the QRS complex from the filtered ECG.
I have a ECG signal along with a respiration signal, I need to filter it to separate the ECG and the Respiration signals. I can apply a FIR/IIR filter or any appropriate method. Also, i need to extract the QRS complex from the filtered ECG. I have attachted the code that I use to filter the signal extract the QRS complex but the results are not satisfying.I have a ECG signal along with a respiration signal, I need to filter it to separate the ECG and the Respiration signals. I can apply a FIR/IIR filter or any appropriate method. Also, i need to extract the QRS complex from the filtered ECG. I have attachted the code that I use to filter the signal extract the QRS complex but the results are not satisfying. I have a ECG signal along with a respiration signal, I need to filter it to separate the ECG and the Respiration signals. I can apply a FIR/IIR filter or any appropriate method. Also, i need to extract the QRS complex from the filtered ECG. I have attachted the code that I use to filter the signal extract the QRS complex but the results are not satisfying. filter, ecg, qrs complex MATLAB Answers — New Questions
Shortcut set for “evaluate selection” not working / responding in Matlab 2022b Update 4
I got o Preferences > Keyboard > Shortcuts and modify the shortcut for ‘Evaluate Selection’ to e.g., command + <.
However, after accepting changes, selecting code in the editor or command window and pressing command + < (or any other attempted shortcut) won’t work.
Any help would be welcome, thank you.I got o Preferences > Keyboard > Shortcuts and modify the shortcut for ‘Evaluate Selection’ to e.g., command + <.
However, after accepting changes, selecting code in the editor or command window and pressing command + < (or any other attempted shortcut) won’t work.
Any help would be welcome, thank you. I got o Preferences > Keyboard > Shortcuts and modify the shortcut for ‘Evaluate Selection’ to e.g., command + <.
However, after accepting changes, selecting code in the editor or command window and pressing command + < (or any other attempted shortcut) won’t work.
Any help would be welcome, thank you. shortcuts, evaluate, selection MATLAB Answers — New Questions
n-way anova with 2 seperate group and 2 seperate data
Hi
Need a help with n-way anova. I’ve got exel table where A and B git values 0 – user incorrect answer and 1 – correct answer, and the labels to them like below:
A = [1 0 1 0 0 1 0]
B = [1 1 0 0 1 1 1]
LabelsA = [red blue white white white blue red]
LabelsB = [high medium medium high low low high]
And now, using the data I need to use anova to create table and multicompare of the stats to see: probability of the case A. Probability of the case 2 and probability A*B.
Additionally i need to draw the all variances probability like: x1 = red x2 = high, x1 = red x2 = medium … x1 = white, x2 = low. so 9 pairs
Tried anova2 but i cannot do all of the variances with groups. Tried anovan but i can input in there only wektor of the data
Would be grateful for any tip.Hi
Need a help with n-way anova. I’ve got exel table where A and B git values 0 – user incorrect answer and 1 – correct answer, and the labels to them like below:
A = [1 0 1 0 0 1 0]
B = [1 1 0 0 1 1 1]
LabelsA = [red blue white white white blue red]
LabelsB = [high medium medium high low low high]
And now, using the data I need to use anova to create table and multicompare of the stats to see: probability of the case A. Probability of the case 2 and probability A*B.
Additionally i need to draw the all variances probability like: x1 = red x2 = high, x1 = red x2 = medium … x1 = white, x2 = low. so 9 pairs
Tried anova2 but i cannot do all of the variances with groups. Tried anovan but i can input in there only wektor of the data
Would be grateful for any tip. Hi
Need a help with n-way anova. I’ve got exel table where A and B git values 0 – user incorrect answer and 1 – correct answer, and the labels to them like below:
A = [1 0 1 0 0 1 0]
B = [1 1 0 0 1 1 1]
LabelsA = [red blue white white white blue red]
LabelsB = [high medium medium high low low high]
And now, using the data I need to use anova to create table and multicompare of the stats to see: probability of the case A. Probability of the case 2 and probability A*B.
Additionally i need to draw the all variances probability like: x1 = red x2 = high, x1 = red x2 = medium … x1 = white, x2 = low. so 9 pairs
Tried anova2 but i cannot do all of the variances with groups. Tried anovan but i can input in there only wektor of the data
Would be grateful for any tip. anova, n-way anova, statistics, probability, ranova, matlab, anova2 MATLAB Answers — New Questions
Unable to get a continuous curvature for my nozzle contour
Greetings everyone, I am trying to fit a Bezier Curve as shown in the paper provide(fig1), but I am unable to get the desired plot(fig 2 and fig3). I have attached the codes as well as the paper and plot. Any help on this is highly appreciated!.
PS: The inflection point is the last point on xarc, i.e, xarc(end) and Nozzle_WithCircARc.m is the main file. It would be better to run the file cell by cell.
%function Nozzle_WithCircARc(G,Me,n,display)
%% Initialize datapoint matrices
clearvars;close all;clc;
G=1.4;
Me = 2.0;
n = 53; % speed index from pucketts paper
display = 0;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%%
%ThetaMax0 = (1.0/1.687)^(2/9) * (NuMax/2);
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
%no_ref = (ThetaMax – ThetaMax_ref)/dT;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0001;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1); % criteria for stopping the reflection from the wall
end
%% Location of wall points
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle
H_in = ywall(end);
L_e = (xwall(end)*(1.0/3.0));
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
%hold on
%contourf(x, y, M, 20, ‘LineColor’, ‘none’); % Draw Mach number contours
%colorbar;
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
end
%% Non-scaled/non-dimensionalized plot
figure (1)
plot(xwall,ywall,’.b’)
title("Non dimensionalized plot")
axis equal
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%%
%{
plot(xwall,ThetaWall)
xlabel(‘xwall’)
ylabel(‘ThetaWall’)
%%
x1 = linspace(min(xwall),max(xwall),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(xwall,ywall,x1,’spline’);
figure;
title(‘Subplot 2: Cubic spline interpolation’)
plot(x1,y1,’r’)
%}
%%
%{
for i = 1:length(M)
M_centerline(i) = M(1,i);
end
for i =1:length(x)
x_axial(i) = x(1,i);
end
plot(x_axial’, Mcenterline’,’r’,’LineWidth’,2)
%}
%% Find the scaling factor
Mexit = Me;
[~,~,~,~,area] = flowisentropic(G,Mexit);
Hexit = 11.2798; %mm
Full_Throat_height = Hexit/area;
half_yt = Full_Throat_height/2.0;
%% Scaling of factors
xarc = half_yt.*xarc;
yarc = half_yt.*yarc;
xwall = half_yt.*xwall;
ywall = half_yt.*ywall;
xconv = half_yt.*xconv;
yconv = half_yt.*yconv;
%% Scaled up coordinates in mm
%{
title("Dimensionalized Plot")
plot(xwall,ywall,’-‘)
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%}
%% Combine Coordinates
% Combine xconv and xwall
coords_new_x = [xconv; xwall];
coords_new_y = [yconv; ywall];
%%
figure (2)
hold on;
plot(xconv, yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,yarc,’.g’,’LineWidth’,1.5) % arc
plot(xconv, -1.*yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, -1.*ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,-1.*yarc,’.g’,’LineWidth’,1.5) % arc
xlabel(‘x [mm]’);
ylabel(‘y [mm]’);
title(‘Scaled up CD nozzle’);
legend(‘Convergent Section’, ‘Straightening Section’, ‘Initial Expansion (Arc)’);
grid on;
axis equal
%% Export coordinates
x1 = linspace(min(coords_new_x ),max(coords_new_x),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(coords_new_x,coords_new_y,x1,’spline’);
x2 = x1′;
y2 = y1′;
%figure;
%plot(x1,y1,’r’)
%writematrix(x2,’Spline.xlsx’,’Sheet’,1,’Range’,’A1′);
%writematrix(y2,’Spline.xlsx’,’Sheet’,1,’Range’,’B1′);
%%
%{
plot(x2,y2)
%%
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
%}
%% Coordinates of wall
%{
writematrix(coords_new_x,’coordinates.xlsx’,’Sheet’,1,’Range’,’A1′);
writematrix(coords_new_y,’coordinates.xlsx’,’Sheet’,1,’Range’,’B1′);
%}
%%
%{
plot(x2,y2,’-k’)
hold on
plot(x2,-1.*(y2),’-r’)
grid on
title("CD Nozzle using a Circular Arc")
axis equal
%}
%% Analyze the discontinuity
% Find second-order derivative of wall contour
dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
dy2_dx2(end-1:end) = NaN; % last two points
%% Bezier Curve
threshold = 0.05; % Define a threshold for discontinuity detection (can be adjusted)
discontinuities = find(abs(diff(dy2_dx2)) > threshold);
%%
if ~isempty(discontinuities)
for idx = 1:length(discontinuities)
point_idx = discontinuities(idx); % Index of discontinuity
% Skip a few points around the discontinuity
region_start = max(1, point_idx – 2); % Upstream region
region_end = min(length(xwall), point_idx + 2); % Downstream region
% Use Bézier curve fitting only in this region to smooth the discontinuity
P0 = [xwall(region_start), ywall(region_start)]; % Start point
P1 = [xwall(point_idx), ywall(point_idx)]; % Control point (inflection/discontinuity)
P2 = [xwall(region_end), ywall(region_end)]; % End point
% Parameter t varies between 0 and 1 to interpolate the Bézier curve
t = linspace(0, 1, region_end – region_start + 1)’;
xwall(region_start:region_end) = (1-t).^2 * P0(1) + 2*(1-t).*t * P1(1) + t.^2 * P2(1);
ywall(region_start:region_end) = (1-t).^2 * P0(2) + 2*(1-t).*t * P1(2) + t.^2 * P2(2);
end
end
%%
plot(xwall,ywall,’.b’)
axis equal
%% Checking for continuous second order derivative of wall contour
cont_dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two (since forward difference needs i+2)
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
cont_dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
cont_dy2_dx2(end-1:end) = NaN;
plot(xwall./xwall(end), dy2_dx2)Greetings everyone, I am trying to fit a Bezier Curve as shown in the paper provide(fig1), but I am unable to get the desired plot(fig 2 and fig3). I have attached the codes as well as the paper and plot. Any help on this is highly appreciated!.
PS: The inflection point is the last point on xarc, i.e, xarc(end) and Nozzle_WithCircARc.m is the main file. It would be better to run the file cell by cell.
%function Nozzle_WithCircARc(G,Me,n,display)
%% Initialize datapoint matrices
clearvars;close all;clc;
G=1.4;
Me = 2.0;
n = 53; % speed index from pucketts paper
display = 0;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%%
%ThetaMax0 = (1.0/1.687)^(2/9) * (NuMax/2);
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
%no_ref = (ThetaMax – ThetaMax_ref)/dT;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0001;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1); % criteria for stopping the reflection from the wall
end
%% Location of wall points
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle
H_in = ywall(end);
L_e = (xwall(end)*(1.0/3.0));
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
%hold on
%contourf(x, y, M, 20, ‘LineColor’, ‘none’); % Draw Mach number contours
%colorbar;
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
end
%% Non-scaled/non-dimensionalized plot
figure (1)
plot(xwall,ywall,’.b’)
title("Non dimensionalized plot")
axis equal
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%%
%{
plot(xwall,ThetaWall)
xlabel(‘xwall’)
ylabel(‘ThetaWall’)
%%
x1 = linspace(min(xwall),max(xwall),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(xwall,ywall,x1,’spline’);
figure;
title(‘Subplot 2: Cubic spline interpolation’)
plot(x1,y1,’r’)
%}
%%
%{
for i = 1:length(M)
M_centerline(i) = M(1,i);
end
for i =1:length(x)
x_axial(i) = x(1,i);
end
plot(x_axial’, Mcenterline’,’r’,’LineWidth’,2)
%}
%% Find the scaling factor
Mexit = Me;
[~,~,~,~,area] = flowisentropic(G,Mexit);
Hexit = 11.2798; %mm
Full_Throat_height = Hexit/area;
half_yt = Full_Throat_height/2.0;
%% Scaling of factors
xarc = half_yt.*xarc;
yarc = half_yt.*yarc;
xwall = half_yt.*xwall;
ywall = half_yt.*ywall;
xconv = half_yt.*xconv;
yconv = half_yt.*yconv;
%% Scaled up coordinates in mm
%{
title("Dimensionalized Plot")
plot(xwall,ywall,’-‘)
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%}
%% Combine Coordinates
% Combine xconv and xwall
coords_new_x = [xconv; xwall];
coords_new_y = [yconv; ywall];
%%
figure (2)
hold on;
plot(xconv, yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,yarc,’.g’,’LineWidth’,1.5) % arc
plot(xconv, -1.*yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, -1.*ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,-1.*yarc,’.g’,’LineWidth’,1.5) % arc
xlabel(‘x [mm]’);
ylabel(‘y [mm]’);
title(‘Scaled up CD nozzle’);
legend(‘Convergent Section’, ‘Straightening Section’, ‘Initial Expansion (Arc)’);
grid on;
axis equal
%% Export coordinates
x1 = linspace(min(coords_new_x ),max(coords_new_x),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(coords_new_x,coords_new_y,x1,’spline’);
x2 = x1′;
y2 = y1′;
%figure;
%plot(x1,y1,’r’)
%writematrix(x2,’Spline.xlsx’,’Sheet’,1,’Range’,’A1′);
%writematrix(y2,’Spline.xlsx’,’Sheet’,1,’Range’,’B1′);
%%
%{
plot(x2,y2)
%%
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
%}
%% Coordinates of wall
%{
writematrix(coords_new_x,’coordinates.xlsx’,’Sheet’,1,’Range’,’A1′);
writematrix(coords_new_y,’coordinates.xlsx’,’Sheet’,1,’Range’,’B1′);
%}
%%
%{
plot(x2,y2,’-k’)
hold on
plot(x2,-1.*(y2),’-r’)
grid on
title("CD Nozzle using a Circular Arc")
axis equal
%}
%% Analyze the discontinuity
% Find second-order derivative of wall contour
dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
dy2_dx2(end-1:end) = NaN; % last two points
%% Bezier Curve
threshold = 0.05; % Define a threshold for discontinuity detection (can be adjusted)
discontinuities = find(abs(diff(dy2_dx2)) > threshold);
%%
if ~isempty(discontinuities)
for idx = 1:length(discontinuities)
point_idx = discontinuities(idx); % Index of discontinuity
% Skip a few points around the discontinuity
region_start = max(1, point_idx – 2); % Upstream region
region_end = min(length(xwall), point_idx + 2); % Downstream region
% Use Bézier curve fitting only in this region to smooth the discontinuity
P0 = [xwall(region_start), ywall(region_start)]; % Start point
P1 = [xwall(point_idx), ywall(point_idx)]; % Control point (inflection/discontinuity)
P2 = [xwall(region_end), ywall(region_end)]; % End point
% Parameter t varies between 0 and 1 to interpolate the Bézier curve
t = linspace(0, 1, region_end – region_start + 1)’;
xwall(region_start:region_end) = (1-t).^2 * P0(1) + 2*(1-t).*t * P1(1) + t.^2 * P2(1);
ywall(region_start:region_end) = (1-t).^2 * P0(2) + 2*(1-t).*t * P1(2) + t.^2 * P2(2);
end
end
%%
plot(xwall,ywall,’.b’)
axis equal
%% Checking for continuous second order derivative of wall contour
cont_dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two (since forward difference needs i+2)
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
cont_dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
cont_dy2_dx2(end-1:end) = NaN;
plot(xwall./xwall(end), dy2_dx2) Greetings everyone, I am trying to fit a Bezier Curve as shown in the paper provide(fig1), but I am unable to get the desired plot(fig 2 and fig3). I have attached the codes as well as the paper and plot. Any help on this is highly appreciated!.
PS: The inflection point is the last point on xarc, i.e, xarc(end) and Nozzle_WithCircARc.m is the main file. It would be better to run the file cell by cell.
%function Nozzle_WithCircARc(G,Me,n,display)
%% Initialize datapoint matrices
clearvars;close all;clc;
G=1.4;
Me = 2.0;
n = 53; % speed index from pucketts paper
display = 0;
Km = zeros(n,n); % K- vlaues (Constant along right running characteristic lines)
Kp = zeros(n,n); % K+ vlaues (Constant along left running characteristic lines)
Theta = zeros(n,n); % Flow angles relative to the horizontal
Mu = zeros(n,n); % Mach angles
M = zeros(n,n); % Mach Numbers
x = zeros(n,n); % x-coordinates
y = zeros(n,n); % y-coordinates
%% Generate the convergent portion of a nozzle
% The inlet height/area and exit height/area(divergent) are same
% Therefore we have same A/A* = 1.6875
% Corresponding to Mach = 0.3722
%% Find NuMax (maximum expansion angle)
[~, NuMax, ~] = PMF(G,Me,0,0);
ThetaMax = NuMax/2;
%%
%ThetaMax0 = (1.0/1.687)^(2/9) * (NuMax/2);
%% Define some flow parameters of originating characteristic lines
dT = ThetaMax/n;
%no_ref = (ThetaMax – ThetaMax_ref)/dT;
ThetaArc(:,1) = (0:dT:ThetaMax);
NuArc = ThetaArc;
KmArc = ThetaArc + NuArc;
[~, ~, MuArc(:,1)] = PMF(G,0,NuArc(:,1),0);
%% Coordinates of wall along curve from throat
y0 = 1; % Define throat half-height
ThroatCurveRadius = 1.5*y0; % Radius of curvature just downstream of the throat
% for larger factors, ywall deviates from A/A* preferred value is 1.1
%L_e = 1.1 * y0 * sind(ThetaMax);
[xarc, yarc] = Arc(ThroatCurveRadius,ThetaArc); % Finds x- and y-coordinates for given theta-values
yarc(:,1) = yarc(:,1) + y0; % Defines offset due to arc being above horizontal
%% Fill in missing datapoint info along first C+ line
% First centerline datapoint done manually
Km(:,1) = KmArc(2:length(KmArc),1);
Theta(:,1) = ThetaArc(2:length(KmArc),1);
Nu(:,1) = Theta(:,1);
Kp(:,1) = Theta(:,1)-Nu(:,1);
M(1,1) = 1.0001;
Nu(1,1) = 0;
Mu(1,1) = 90;
y(1,1) = 0;
x(1,1) = xarc(2,1) + (y(1,1) – yarc(2,1))/tand((ThetaArc(2,1) – MuArc(2,1) – MuArc(2,1))/2);
% Finds the information at interior nodes along first C+ line
for i=2:n
[M(i,1), Nu(i,1), Mu(i,1)] = PMF(G,0,Nu(i,1),0);
s1 = tand((ThetaArc(i+1,1) – MuArc(i+1,1) + Theta(i,1) – Mu(i,1))/2);
s2 = tand((Theta(i-1,1) + Mu(i-1,1) + Theta(i,1) + Mu(i,1))/2);
x(i,1) = ((y(i-1,1)-x(i-1,1)*s2)-(yarc(i+1,1)-xarc(i+1,1)*s1))/(s1-s2);
y(i,1) = y(i-1,1) + (x(i,1)-x(i-1,1))*s2;
end
%% Find flow properties at remaining interior nodes
for j=2:n;
for i=1:n+1-j;
Km(i,j) = Km(i+1,j-1);
if i==1;
Theta(i,j) = 0;
Kp(i,j) = -Km(i,j);
Nu(i,j) = Km(i,j);
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
x(i,j) = x(i+1,j-1) – y(i+1,j-1)/s1;
y(i,j) = 0;
else
Kp(i,j) = Kp(i-1,j);
Theta(i,j) = (Km(i,j)+Kp(i,j))/2;
Nu(i,j) = (Km(i,j)-Kp(i,j))/2;
[M(i,j), Nu(i,j), Mu(i,j)] = PMF(G,0,Nu(i,j),0);
s1 = tand((Theta(i+1,j-1)-Mu(i+1,j-1)+Theta(i,j)-Mu(i,j))/2);
s2 = tand((Theta(i-1,j)+Mu(i-1,j)+Theta(i,j)+Mu(i,j))/2);
x(i,j) = ((y(i-1,j)-x(i-1,j)*s2)-(y(i+1,j-1)-x(i+1,j-1)*s1))/(s1-s2);
y(i,j) = y(i-1,j) + (x(i,j)-x(i-1,j))*s2;
end
end
end
%% Find wall node information
xwall = zeros(2*n,1);
ywall = xwall;
ThetaWall = ywall;
xwall(1:n,1) = xarc(2:length(xarc),1);
ywall(1:n,1) = yarc(2:length(xarc),1);
ThetaWall(1:n,1) = ThetaArc(2:length(xarc),1);
for i=1:n-1
ThetaWall(n+i,1) = ThetaWall(n-i,1); % criteria for stopping the reflection from the wall
end
%% Location of wall points
for i=1:n
s1 = tand((ThetaWall(n+i-1,1) + ThetaWall(n+i,1))/2);
s2 = tand(Theta(n+1-i,i)+Mu(n+1-i,i));
xwall(n+i,1) = ((y(n+1-i,i)-x(n+1-i,i)*s2)-(ywall(n+i-1,1)-xwall(n+i-1,1)*s1))/(s1-s2);
ywall(n+i,1) = ywall(n+i-1,1) + (xwall(n+i,1)-xwall(n+i-1,1))*s1;
end
%% Provide wall geometry to user
assignin(‘caller’,’xwall’,xwall)
assignin(‘caller’,’ywall’,ywall)
assignin(‘caller’,’Coords’,[xwall ywall])
%% Generate the convergent portion of nozzle
H_in = ywall(end);
L_e = (xwall(end)*(1.0/3.0));
[xconv,yconv] = Convergent_new_3rd(y0,H_in,L_e,n);
%%
% Draw contour and characteristic web
if display == 1
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
for i=1:n-1
plot(x(1:n+1-i,i),y(1:n+1-i,i))
end
for i=1:n
plot([xarc(i,1) x(i,1)],[yarc(i,1) y(i,1)])
plot([x(n+1-i,i) xwall(i+n,1)],[y(n+1-i,i) ywall(i+n,1)])
end
for c=1:n
for r=2:n+1-c
plot([x(c,r) x(c+1,r-1)],[y(c,r) y(c+1,r-1)])
end
end
%hold on
%contourf(x, y, M, 20, ‘LineColor’, ‘none’); % Draw Mach number contours
%colorbar;
xlabel(‘Length [x/y0]’)
ylabel(‘Height [y/y0]’)
end
%% Non-scaled/non-dimensionalized plot
figure (1)
plot(xwall,ywall,’.b’)
title("Non dimensionalized plot")
axis equal
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%%
%{
plot(xwall,ThetaWall)
xlabel(‘xwall’)
ylabel(‘ThetaWall’)
%%
x1 = linspace(min(xwall),max(xwall),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(xwall,ywall,x1,’spline’);
figure;
title(‘Subplot 2: Cubic spline interpolation’)
plot(x1,y1,’r’)
%}
%%
%{
for i = 1:length(M)
M_centerline(i) = M(1,i);
end
for i =1:length(x)
x_axial(i) = x(1,i);
end
plot(x_axial’, Mcenterline’,’r’,’LineWidth’,2)
%}
%% Find the scaling factor
Mexit = Me;
[~,~,~,~,area] = flowisentropic(G,Mexit);
Hexit = 11.2798; %mm
Full_Throat_height = Hexit/area;
half_yt = Full_Throat_height/2.0;
%% Scaling of factors
xarc = half_yt.*xarc;
yarc = half_yt.*yarc;
xwall = half_yt.*xwall;
ywall = half_yt.*ywall;
xconv = half_yt.*xconv;
yconv = half_yt.*yconv;
%% Scaled up coordinates in mm
%{
title("Dimensionalized Plot")
plot(xwall,ywall,’-‘)
hold on
plot(xarc,yarc,’-‘)
hold on
plot(xconv,yconv,’-‘)
xlabel(‘xwall’)
ylabel(‘ywall’)
axis equal
%}
%% Combine Coordinates
% Combine xconv and xwall
coords_new_x = [xconv; xwall];
coords_new_y = [yconv; ywall];
%%
figure (2)
hold on;
plot(xconv, yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,yarc,’.g’,’LineWidth’,1.5) % arc
plot(xconv, -1.*yconv, ‘.b’, ‘LineWidth’, 1.5) % Convergent section
plot(xwall, -1.*ywall, ‘.r’, ‘LineWidth’, 1.5) % Wall section
plot(xarc,-1.*yarc,’.g’,’LineWidth’,1.5) % arc
xlabel(‘x [mm]’);
ylabel(‘y [mm]’);
title(‘Scaled up CD nozzle’);
legend(‘Convergent Section’, ‘Straightening Section’, ‘Initial Expansion (Arc)’);
grid on;
axis equal
%% Export coordinates
x1 = linspace(min(coords_new_x ),max(coords_new_x),1000);
%y1 = spline(xw,yw,x1);
y1 = interp1(coords_new_x,coords_new_y,x1,’spline’);
x2 = x1′;
y2 = y1′;
%figure;
%plot(x1,y1,’r’)
%writematrix(x2,’Spline.xlsx’,’Sheet’,1,’Range’,’A1′);
%writematrix(y2,’Spline.xlsx’,’Sheet’,1,’Range’,’B1′);
%%
%{
plot(x2,y2)
%%
plot(xwall,ywall,’-‘)
axis equal
axis([0 ceil(xwall(length(xwall),1)) 0 ceil(ywall(length(ywall),1))])
hold on
plot(xarc,yarc,’k-‘)
%}
%% Coordinates of wall
%{
writematrix(coords_new_x,’coordinates.xlsx’,’Sheet’,1,’Range’,’A1′);
writematrix(coords_new_y,’coordinates.xlsx’,’Sheet’,1,’Range’,’B1′);
%}
%%
%{
plot(x2,y2,’-k’)
hold on
plot(x2,-1.*(y2),’-r’)
grid on
title("CD Nozzle using a Circular Arc")
axis equal
%}
%% Analyze the discontinuity
% Find second-order derivative of wall contour
dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
dy2_dx2(end-1:end) = NaN; % last two points
%% Bezier Curve
threshold = 0.05; % Define a threshold for discontinuity detection (can be adjusted)
discontinuities = find(abs(diff(dy2_dx2)) > threshold);
%%
if ~isempty(discontinuities)
for idx = 1:length(discontinuities)
point_idx = discontinuities(idx); % Index of discontinuity
% Skip a few points around the discontinuity
region_start = max(1, point_idx – 2); % Upstream region
region_end = min(length(xwall), point_idx + 2); % Downstream region
% Use Bézier curve fitting only in this region to smooth the discontinuity
P0 = [xwall(region_start), ywall(region_start)]; % Start point
P1 = [xwall(point_idx), ywall(point_idx)]; % Control point (inflection/discontinuity)
P2 = [xwall(region_end), ywall(region_end)]; % End point
% Parameter t varies between 0 and 1 to interpolate the Bézier curve
t = linspace(0, 1, region_end – region_start + 1)’;
xwall(region_start:region_end) = (1-t).^2 * P0(1) + 2*(1-t).*t * P1(1) + t.^2 * P2(1);
ywall(region_start:region_end) = (1-t).^2 * P0(2) + 2*(1-t).*t * P1(2) + t.^2 * P2(2);
end
end
%%
plot(xwall,ywall,’.b’)
axis equal
%% Checking for continuous second order derivative of wall contour
cont_dy2_dx2 = zeros(size(xwall));
% Loop over all points except the last two (since forward difference needs i+2)
for i = 1:length(xwall)-2
% Calculate the second-order derivative using the forward difference formula
cont_dy2_dx2(i) = (ywall(i+2) – 2*ywall(i+1) + ywall(i)) / (xwall(i+1) – xwall(i))^2;
end
cont_dy2_dx2(end-1:end) = NaN;
plot(xwall./xwall(end), dy2_dx2) #curve fitting, bezier, forward difference MATLAB Answers — New Questions
QUARTERLY AVERAGE AND VARIANCE from MONTHLY DATA
I have a dataset of windspeed for each district of INDIA by month for 50 years (only the first seven are displayed below). I want to find the QUARTERLY average and VARIANCE for each district. Any help would be appreciated. Data example below
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str27 state str24 districts float(latitude longitude) byte month float(ws_2023 ws_2022 ws_2021 ws_2020 ws_2019 ws_2018 ws_2017)
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 1 4.589247 3.613052 4.267717 4.635023 4.930599 3.780835 4.673967
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 2 4.079226 4.215449 3.877388 4.538066 3.682131 3.676485 3.948466
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 3 3.171698 2.644508 2.92275 3.351344 3.177872 2.893883 3.182198
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 4 2.689871 2.156992 2.136186 2.872274 2.989198 2.722031 2.906296
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 5 4.14325 5.455741 3.406546 3.855165 3.735876 2.974356 3.366552
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 6 5.78509 4.582315 5.06107 4.991875 5.848218 6.734819 6.140237
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 7 6.180731 4.725333 5.93688 4.066154 5.917521 6.973715 5.876394
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 8 5.776236 5.244017 4.860325 5.294113 7.112219 7.073696 5.248257
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 9 5.926691 4.340836 4.858127 4.631201 4.920815 4.280732 4.387124
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 10 2.832476 4.086142 3.879084 3.524881 2.504806 3.259824 3.722174
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 11 3.89687 3.366515 4.069301 4.236919 3.831769 4.167921 4.207607
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 12 4.377546 4.54319 4.715546 4.315512 4.674977 4.296709 4.937579
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 1 6.210341 4.802261 6.2101 6.206068 6.416927 4.771069 6.214251
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 2 5.469119 5.677119 5.161079 6.119121 5.056155 5.20627 5.359843
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 3 4.022772 3.287575 3.717183 3.603297 3.418595 3.492516 3.59089
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 4 3.014578 2.633554 2.704057 3.562704 3.44037 3.314805 3.605515
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 5 5.758973 7.633964 4.783988 5.456239 5.274939 3.910879 4.607275
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 6 8.273372 6.252726 7.027379 7.017265 8.193433 9.077105 8.145121
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 7 8.684149 7.11254 8.41686 5.523673 7.773966 9.72518 8.343679
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 8 8.257681 7.702024 7.115208 7.253097 9.670324 9.874477 7.653042
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 9 8.256769 6.616227 6.917697 6.731298 6.786049 5.860077 6.402016
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 10 3.68233 4.764365 5.604181 5.805154 3.288253 3.944639 5.052252
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 11 5.013813 4.12091 4.951137 5.162457 5.361066 5.314161 4.652676
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 12 5.805525 6.347145 6.215302 5.600912 6.451589 5.682451 6.354571
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 1 2.071669 1.906998 1.939836 2.075697 2.161556 1.867749 2.186907
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 2 2.252566 2.123164 2.052436 2.442608 2.446047 2.056368 2.235332
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 3 2.232489 2.296364 2.168355 2.435328 2.616105 2.0682 2.37214
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 4 2.163504 2.317636 2.062944 2.230672 2.365663 2.306504 2.151902
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 5 2.233094 2.828299 2.821097 2.442079 2.263708 2.127188 2.934911
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 6 3.514094 2.797159 3.412144 3.196953 3.428785 3.854449 3.74473
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 7 4.419012 3.583243 3.530141 2.285392 3.653605 4.687582 4.112722
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 8 2.849966 3.091185 2.984837 3.136886 3.922278 5.022915 2.880093
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 9 2.927668 2.581071 2.732151 2.731299 2.755776 2.25119 2.190346
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 10 1.935015 2.111777 1.777521 2.475076 1.535323 1.955869 1.695318
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 11 2.019673 2.092834 2.257045 2.613384 2.126691 2.197218 2.132412
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 12 2.483747 2.478249 1.963105 2.345541 2.264333 2.242998 2.073321
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 1 1.987441 1.91066 1.86635 1.984144 1.924251 1.669018 1.983049
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 2 1.724246 1.956904 1.953315 2.075664 1.991458 1.761446 1.777079
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 3 1.760321 1.935036 1.757222 1.722926 1.879776 1.877282 1.911202
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 4 1.681082 2.006113 1.659624 1.749227 1.864686 1.898789 2.223191
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 5 1.778992 2.451346 2.086234 1.976747 2.230505 1.910879 1.914892
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 6 2.416438 2.145792 2.653355 2.153984 2.45271 2.329058 2.48887
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 7 3.393621 3.058341 2.791372 2.005118 2.855509 3.480551 3.17864
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 8 2.665884 2.605833 2.375462 3.258956 3.166419 3.685513 2.249233
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 9 2.15716 2.018571 2.208713 1.722998 2.432045 1.953339 1.662759
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 10 1.6794 1.821005 1.460138 1.546854 1.725753 1.699766 1.331305
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 11 2.362202 1.841369 2.649868 2.37022 1.928938 1.887892 1.993252
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 12 2.372175 2.15403 1.945038 1.970053 2.424489 2.20125 1.92171
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 1 2.011366 2.08107 1.888078 2.175307 2.046566 1.711987 2.04384
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 2 1.931765 2.307734 2.067085 2.44749 2.500002 1.985567 2.09666
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 3 2.373602 2.458717 2.115621 2.740993 2.991105 2.510094 2.925362
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 4 2.548758 2.958261 2.527299 2.988973 3.118593 3.251816 2.894578
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 5 2.386414 3.009452 3.237601 2.876161 3.080603 3.112051 2.889013
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 6 3.161067 3.017374 3.293492 2.636406 3.111402 2.99898 2.789651
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 7 3.664129 3.093009 3.062856 2.255607 3.121134 3.479086 3.147878
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 8 2.84606 2.704954 2.66013 3.023605 3.152747 3.65231 2.367398
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 9 2.383722 2.29152 2.370334 2.238135 2.599038 2.126679 1.888833
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 10 1.867388 1.978476 1.748224 1.915506 1.639327 2.064756 1.631842
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 11 2.148823 1.817687 2.462612 2.304302 1.947004 2.018751 2.124355
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 12 2.385847 2.008522 2.1362 2.018637 2.262868 2.301592 2.08919
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 1 2.016982 2.063248 1.918352 2.203383 1.990902 1.675122 2.033587
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 2 1.856081 2.255 2.059272 2.462871 2.399661 1.932588 1.99705
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 3 2.299871 2.319313 1.99648 2.563258 2.707413 2.299645 2.696358
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 4 2.327566 2.709238 2.341753 2.732137 2.801698 2.962754 2.68071
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 5 2.228699 3.014823 3.060355 2.668153 2.813513 2.880606 2.612157
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 6 3.126399 2.921671 3.138706 2.625664 3.053785 2.862261 2.795511
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 7 3.683172 3.185294 3.050161 2.216544 3.118937 3.509848 3.201589
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 8 2.813833 2.691771 2.644016 3.143722 3.177161 3.748501 2.381069
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 9 2.350031 2.26027 2.358615 2.152197 2.562905 2.069306 1.837807
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 10 1.858355 1.990195 1.677424 1.873514 1.681808 1.952695 1.604742
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 11 2.297016 1.859923 2.603725 2.351421 2.027082 2.004835 2.172207
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 12 2.444685 2.104958 2.152802 2.059896 2.402516 2.272051 2.0992
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 1 2.056532 1.886978 1.878557 2.033217 2.102474 1.978589 2.157366
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 2 2.212771 2.158808 2.061958 2.473369 2.435305 2.272676 2.309306
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 3 2.228094 2.156715 2.145406 2.709743 2.781388 2.305505 2.603585
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 4 2.488699 2.457773 2.239213 2.510946 2.591737 2.673691 2.364792
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 5 2.438172 2.945487 3.199027 2.526551 2.601599 2.514883 2.920263
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 6 3.734309 3.287393 3.806187 3.250664 3.603101 4.160601 3.837503
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 7 4.495672 3.738028 3.756704 2.563712 4.048136 4.704184 3.989675
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 8 3.301626 3.308958 3.112278 3.540206 4.179602 4.823696 2.978726
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 9 3.134211 2.628434 3.065647 2.743994 2.827065 2.477021 2.204995
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 10 2.264361 1.964804 1.912775 2.033182 1.671065 2.17169 1.69776
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 11 2.124653 1.995422 2.382534 2.313824 1.98924 2.006056 2.220546
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 12 2.34654 2.072243 1.885468 2.081381 2.116383 2.190996 2.209795
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 1 2.44496 2.590836 2.425676 2.605971 2.501644 2.515942 2.757463
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 2 2.508425 2.762568 2.567573 3.126446 3.197756 2.60129 2.800029
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 3 3.205389 3.237282 2.953511 3.691676 4.10756 3.36654 4.029366
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 4 3.662039 3.821054 3.530229 3.994833 4.279237 4.280625 4.094285
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 5 3.212586 3.671073 4.05303 3.806825 4.215857 3.95336 3.870458
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 6 3.785578 3.46171 3.949253 3.267265 3.760816 3.631304 3.623147
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 7 4.028875 3.644278 3.422719 2.675529 3.510783 4.426352 3.740652
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 8 3.309439 3.221068 3.280735 2.928878 3.648352 4.515591 3.001187
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 9 3.065851 2.845231 2.899631 2.802588 3.053627 2.959442 2.436929
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 10 2.54024 2.594199 2.424494 2.607889 2.401534 2.679014 2.344
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 11 2.683003 2.720275 3.157192 3.142681 2.674055 2.672804 2.926601
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 12 3.434187 2.877907 2.651093 3.038168 2.910573 2.87581 2.851641
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 1 3.073378 3.212418 2.792619 3.054945 2.819027 2.648022 2.986223
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 2 3.036501 3.030879 3.170356 3.00584 3.223879 2.857637 2.92332
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 3 3.2237 3.786842 3.660542 3.183375 4.176651 4.108239 4.844308
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 4 3.600516 5.530527 4.27437 4.589071 4.829042 5.10582 5.711472
endI have a dataset of windspeed for each district of INDIA by month for 50 years (only the first seven are displayed below). I want to find the QUARTERLY average and VARIANCE for each district. Any help would be appreciated. Data example below
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str27 state str24 districts float(latitude longitude) byte month float(ws_2023 ws_2022 ws_2021 ws_2020 ws_2019 ws_2018 ws_2017)
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 1 4.589247 3.613052 4.267717 4.635023 4.930599 3.780835 4.673967
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 2 4.079226 4.215449 3.877388 4.538066 3.682131 3.676485 3.948466
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 3 3.171698 2.644508 2.92275 3.351344 3.177872 2.893883 3.182198
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 4 2.689871 2.156992 2.136186 2.872274 2.989198 2.722031 2.906296
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 5 4.14325 5.455741 3.406546 3.855165 3.735876 2.974356 3.366552
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 6 5.78509 4.582315 5.06107 4.991875 5.848218 6.734819 6.140237
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 7 6.180731 4.725333 5.93688 4.066154 5.917521 6.973715 5.876394
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 8 5.776236 5.244017 4.860325 5.294113 7.112219 7.073696 5.248257
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 9 5.926691 4.340836 4.858127 4.631201 4.920815 4.280732 4.387124
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 10 2.832476 4.086142 3.879084 3.524881 2.504806 3.259824 3.722174
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 11 3.89687 3.366515 4.069301 4.236919 3.831769 4.167921 4.207607
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 12 4.377546 4.54319 4.715546 4.315512 4.674977 4.296709 4.937579
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 1 6.210341 4.802261 6.2101 6.206068 6.416927 4.771069 6.214251
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 2 5.469119 5.677119 5.161079 6.119121 5.056155 5.20627 5.359843
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 3 4.022772 3.287575 3.717183 3.603297 3.418595 3.492516 3.59089
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 4 3.014578 2.633554 2.704057 3.562704 3.44037 3.314805 3.605515
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 5 5.758973 7.633964 4.783988 5.456239 5.274939 3.910879 4.607275
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 6 8.273372 6.252726 7.027379 7.017265 8.193433 9.077105 8.145121
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 7 8.684149 7.11254 8.41686 5.523673 7.773966 9.72518 8.343679
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 8 8.257681 7.702024 7.115208 7.253097 9.670324 9.874477 7.653042
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 9 8.256769 6.616227 6.917697 6.731298 6.786049 5.860077 6.402016
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 10 3.68233 4.764365 5.604181 5.805154 3.288253 3.944639 5.052252
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 11 5.013813 4.12091 4.951137 5.162457 5.361066 5.314161 4.652676
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 12 5.805525 6.347145 6.215302 5.600912 6.451589 5.682451 6.354571
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 1 2.071669 1.906998 1.939836 2.075697 2.161556 1.867749 2.186907
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 2 2.252566 2.123164 2.052436 2.442608 2.446047 2.056368 2.235332
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 3 2.232489 2.296364 2.168355 2.435328 2.616105 2.0682 2.37214
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 4 2.163504 2.317636 2.062944 2.230672 2.365663 2.306504 2.151902
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 5 2.233094 2.828299 2.821097 2.442079 2.263708 2.127188 2.934911
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 6 3.514094 2.797159 3.412144 3.196953 3.428785 3.854449 3.74473
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 7 4.419012 3.583243 3.530141 2.285392 3.653605 4.687582 4.112722
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 8 2.849966 3.091185 2.984837 3.136886 3.922278 5.022915 2.880093
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 9 2.927668 2.581071 2.732151 2.731299 2.755776 2.25119 2.190346
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 10 1.935015 2.111777 1.777521 2.475076 1.535323 1.955869 1.695318
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 11 2.019673 2.092834 2.257045 2.613384 2.126691 2.197218 2.132412
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 12 2.483747 2.478249 1.963105 2.345541 2.264333 2.242998 2.073321
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 1 1.987441 1.91066 1.86635 1.984144 1.924251 1.669018 1.983049
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 2 1.724246 1.956904 1.953315 2.075664 1.991458 1.761446 1.777079
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 3 1.760321 1.935036 1.757222 1.722926 1.879776 1.877282 1.911202
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 4 1.681082 2.006113 1.659624 1.749227 1.864686 1.898789 2.223191
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 5 1.778992 2.451346 2.086234 1.976747 2.230505 1.910879 1.914892
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 6 2.416438 2.145792 2.653355 2.153984 2.45271 2.329058 2.48887
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 7 3.393621 3.058341 2.791372 2.005118 2.855509 3.480551 3.17864
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 8 2.665884 2.605833 2.375462 3.258956 3.166419 3.685513 2.249233
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 9 2.15716 2.018571 2.208713 1.722998 2.432045 1.953339 1.662759
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 10 1.6794 1.821005 1.460138 1.546854 1.725753 1.699766 1.331305
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 11 2.362202 1.841369 2.649868 2.37022 1.928938 1.887892 1.993252
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 12 2.372175 2.15403 1.945038 1.970053 2.424489 2.20125 1.92171
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 1 2.011366 2.08107 1.888078 2.175307 2.046566 1.711987 2.04384
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 2 1.931765 2.307734 2.067085 2.44749 2.500002 1.985567 2.09666
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 3 2.373602 2.458717 2.115621 2.740993 2.991105 2.510094 2.925362
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 4 2.548758 2.958261 2.527299 2.988973 3.118593 3.251816 2.894578
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 5 2.386414 3.009452 3.237601 2.876161 3.080603 3.112051 2.889013
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 6 3.161067 3.017374 3.293492 2.636406 3.111402 2.99898 2.789651
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 7 3.664129 3.093009 3.062856 2.255607 3.121134 3.479086 3.147878
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 8 2.84606 2.704954 2.66013 3.023605 3.152747 3.65231 2.367398
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 9 2.383722 2.29152 2.370334 2.238135 2.599038 2.126679 1.888833
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 10 1.867388 1.978476 1.748224 1.915506 1.639327 2.064756 1.631842
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 11 2.148823 1.817687 2.462612 2.304302 1.947004 2.018751 2.124355
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 12 2.385847 2.008522 2.1362 2.018637 2.262868 2.301592 2.08919
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 1 2.016982 2.063248 1.918352 2.203383 1.990902 1.675122 2.033587
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 2 1.856081 2.255 2.059272 2.462871 2.399661 1.932588 1.99705
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 3 2.299871 2.319313 1.99648 2.563258 2.707413 2.299645 2.696358
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 4 2.327566 2.709238 2.341753 2.732137 2.801698 2.962754 2.68071
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 5 2.228699 3.014823 3.060355 2.668153 2.813513 2.880606 2.612157
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 6 3.126399 2.921671 3.138706 2.625664 3.053785 2.862261 2.795511
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 7 3.683172 3.185294 3.050161 2.216544 3.118937 3.509848 3.201589
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 8 2.813833 2.691771 2.644016 3.143722 3.177161 3.748501 2.381069
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 9 2.350031 2.26027 2.358615 2.152197 2.562905 2.069306 1.837807
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 10 1.858355 1.990195 1.677424 1.873514 1.681808 1.952695 1.604742
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 11 2.297016 1.859923 2.603725 2.351421 2.027082 2.004835 2.172207
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 12 2.444685 2.104958 2.152802 2.059896 2.402516 2.272051 2.0992
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 1 2.056532 1.886978 1.878557 2.033217 2.102474 1.978589 2.157366
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 2 2.212771 2.158808 2.061958 2.473369 2.435305 2.272676 2.309306
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 3 2.228094 2.156715 2.145406 2.709743 2.781388 2.305505 2.603585
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 4 2.488699 2.457773 2.239213 2.510946 2.591737 2.673691 2.364792
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 5 2.438172 2.945487 3.199027 2.526551 2.601599 2.514883 2.920263
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 6 3.734309 3.287393 3.806187 3.250664 3.603101 4.160601 3.837503
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 7 4.495672 3.738028 3.756704 2.563712 4.048136 4.704184 3.989675
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 8 3.301626 3.308958 3.112278 3.540206 4.179602 4.823696 2.978726
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 9 3.134211 2.628434 3.065647 2.743994 2.827065 2.477021 2.204995
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 10 2.264361 1.964804 1.912775 2.033182 1.671065 2.17169 1.69776
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 11 2.124653 1.995422 2.382534 2.313824 1.98924 2.006056 2.220546
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 12 2.34654 2.072243 1.885468 2.081381 2.116383 2.190996 2.209795
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 1 2.44496 2.590836 2.425676 2.605971 2.501644 2.515942 2.757463
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 2 2.508425 2.762568 2.567573 3.126446 3.197756 2.60129 2.800029
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 3 3.205389 3.237282 2.953511 3.691676 4.10756 3.36654 4.029366
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 4 3.662039 3.821054 3.530229 3.994833 4.279237 4.280625 4.094285
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 5 3.212586 3.671073 4.05303 3.806825 4.215857 3.95336 3.870458
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 6 3.785578 3.46171 3.949253 3.267265 3.760816 3.631304 3.623147
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 7 4.028875 3.644278 3.422719 2.675529 3.510783 4.426352 3.740652
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 8 3.309439 3.221068 3.280735 2.928878 3.648352 4.515591 3.001187
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 9 3.065851 2.845231 2.899631 2.802588 3.053627 2.959442 2.436929
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 10 2.54024 2.594199 2.424494 2.607889 2.401534 2.679014 2.344
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 11 2.683003 2.720275 3.157192 3.142681 2.674055 2.672804 2.926601
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 12 3.434187 2.877907 2.651093 3.038168 2.910573 2.87581 2.851641
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 1 3.073378 3.212418 2.792619 3.054945 2.819027 2.648022 2.986223
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 2 3.036501 3.030879 3.170356 3.00584 3.223879 2.857637 2.92332
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 3 3.2237 3.786842 3.660542 3.183375 4.176651 4.108239 4.844308
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 4 3.600516 5.530527 4.27437 4.589071 4.829042 5.10582 5.711472
end I have a dataset of windspeed for each district of INDIA by month for 50 years (only the first seven are displayed below). I want to find the QUARTERLY average and VARIANCE for each district. Any help would be appreciated. Data example below
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str27 state str24 districts float(latitude longitude) byte month float(ws_2023 ws_2022 ws_2021 ws_2020 ws_2019 ws_2018 ws_2017)
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 1 4.589247 3.613052 4.267717 4.635023 4.930599 3.780835 4.673967
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 2 4.079226 4.215449 3.877388 4.538066 3.682131 3.676485 3.948466
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 3 3.171698 2.644508 2.92275 3.351344 3.177872 2.893883 3.182198
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 4 2.689871 2.156992 2.136186 2.872274 2.989198 2.722031 2.906296
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 5 4.14325 5.455741 3.406546 3.855165 3.735876 2.974356 3.366552
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 6 5.78509 4.582315 5.06107 4.991875 5.848218 6.734819 6.140237
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 7 6.180731 4.725333 5.93688 4.066154 5.917521 6.973715 5.876394
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 8 5.776236 5.244017 4.860325 5.294113 7.112219 7.073696 5.248257
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 9 5.926691 4.340836 4.858127 4.631201 4.920815 4.280732 4.387124
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 10 2.832476 4.086142 3.879084 3.524881 2.504806 3.259824 3.722174
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 11 3.89687 3.366515 4.069301 4.236919 3.831769 4.167921 4.207607
"ANDAMAN AND NICOBAR ISLANDS" "North and Middle Andaman" 12.5601 92.8976 12 4.377546 4.54319 4.715546 4.315512 4.674977 4.296709 4.937579
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 1 6.210341 4.802261 6.2101 6.206068 6.416927 4.771069 6.214251
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 2 5.469119 5.677119 5.161079 6.119121 5.056155 5.20627 5.359843
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 3 4.022772 3.287575 3.717183 3.603297 3.418595 3.492516 3.59089
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 4 3.014578 2.633554 2.704057 3.562704 3.44037 3.314805 3.605515
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 5 5.758973 7.633964 4.783988 5.456239 5.274939 3.910879 4.607275
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 6 8.273372 6.252726 7.027379 7.017265 8.193433 9.077105 8.145121
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 7 8.684149 7.11254 8.41686 5.523673 7.773966 9.72518 8.343679
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 8 8.257681 7.702024 7.115208 7.253097 9.670324 9.874477 7.653042
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 9 8.256769 6.616227 6.917697 6.731298 6.786049 5.860077 6.402016
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 10 3.68233 4.764365 5.604181 5.805154 3.288253 3.944639 5.052252
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 11 5.013813 4.12091 4.951137 5.162457 5.361066 5.314161 4.652676
"ANDAMAN AND NICOBAR ISLANDS" "South Andaman" 10.7449 92.5 12 5.805525 6.347145 6.215302 5.600912 6.451589 5.682451 6.354571
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 1 2.071669 1.906998 1.939836 2.075697 2.161556 1.867749 2.186907
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 2 2.252566 2.123164 2.052436 2.442608 2.446047 2.056368 2.235332
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 3 2.232489 2.296364 2.168355 2.435328 2.616105 2.0682 2.37214
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 4 2.163504 2.317636 2.062944 2.230672 2.365663 2.306504 2.151902
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 5 2.233094 2.828299 2.821097 2.442079 2.263708 2.127188 2.934911
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 6 3.514094 2.797159 3.412144 3.196953 3.428785 3.854449 3.74473
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 7 4.419012 3.583243 3.530141 2.285392 3.653605 4.687582 4.112722
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 8 2.849966 3.091185 2.984837 3.136886 3.922278 5.022915 2.880093
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 9 2.927668 2.581071 2.732151 2.731299 2.755776 2.25119 2.190346
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 10 1.935015 2.111777 1.777521 2.475076 1.535323 1.955869 1.695318
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 11 2.019673 2.092834 2.257045 2.613384 2.126691 2.197218 2.132412
"ANDHRA PRADESH" "Chittoor" 13.2172 79.1003 12 2.483747 2.478249 1.963105 2.345541 2.264333 2.242998 2.073321
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 1 1.987441 1.91066 1.86635 1.984144 1.924251 1.669018 1.983049
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 2 1.724246 1.956904 1.953315 2.075664 1.991458 1.761446 1.777079
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 3 1.760321 1.935036 1.757222 1.722926 1.879776 1.877282 1.911202
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 4 1.681082 2.006113 1.659624 1.749227 1.864686 1.898789 2.223191
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 5 1.778992 2.451346 2.086234 1.976747 2.230505 1.910879 1.914892
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 6 2.416438 2.145792 2.653355 2.153984 2.45271 2.329058 2.48887
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 7 3.393621 3.058341 2.791372 2.005118 2.855509 3.480551 3.17864
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 8 2.665884 2.605833 2.375462 3.258956 3.166419 3.685513 2.249233
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 9 2.15716 2.018571 2.208713 1.722998 2.432045 1.953339 1.662759
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 10 1.6794 1.821005 1.460138 1.546854 1.725753 1.699766 1.331305
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 11 2.362202 1.841369 2.649868 2.37022 1.928938 1.887892 1.993252
"ANDHRA PRADESH" "East Godavari" 17.3213 82.0407 12 2.372175 2.15403 1.945038 1.970053 2.424489 2.20125 1.92171
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 1 2.011366 2.08107 1.888078 2.175307 2.046566 1.711987 2.04384
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 2 1.931765 2.307734 2.067085 2.44749 2.500002 1.985567 2.09666
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 3 2.373602 2.458717 2.115621 2.740993 2.991105 2.510094 2.925362
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 4 2.548758 2.958261 2.527299 2.988973 3.118593 3.251816 2.894578
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 5 2.386414 3.009452 3.237601 2.876161 3.080603 3.112051 2.889013
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 6 3.161067 3.017374 3.293492 2.636406 3.111402 2.99898 2.789651
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 7 3.664129 3.093009 3.062856 2.255607 3.121134 3.479086 3.147878
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 8 2.84606 2.704954 2.66013 3.023605 3.152747 3.65231 2.367398
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 9 2.383722 2.29152 2.370334 2.238135 2.599038 2.126679 1.888833
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 10 1.867388 1.978476 1.748224 1.915506 1.639327 2.064756 1.631842
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 11 2.148823 1.817687 2.462612 2.304302 1.947004 2.018751 2.124355
"ANDHRA PRADESH" "Guntur" 16.3067 80.4365 12 2.385847 2.008522 2.1362 2.018637 2.262868 2.301592 2.08919
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 1 2.016982 2.063248 1.918352 2.203383 1.990902 1.675122 2.033587
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 2 1.856081 2.255 2.059272 2.462871 2.399661 1.932588 1.99705
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 3 2.299871 2.319313 1.99648 2.563258 2.707413 2.299645 2.696358
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 4 2.327566 2.709238 2.341753 2.732137 2.801698 2.962754 2.68071
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 5 2.228699 3.014823 3.060355 2.668153 2.813513 2.880606 2.612157
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 6 3.126399 2.921671 3.138706 2.625664 3.053785 2.862261 2.795511
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 7 3.683172 3.185294 3.050161 2.216544 3.118937 3.509848 3.201589
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 8 2.813833 2.691771 2.644016 3.143722 3.177161 3.748501 2.381069
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 9 2.350031 2.26027 2.358615 2.152197 2.562905 2.069306 1.837807
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 10 1.858355 1.990195 1.677424 1.873514 1.681808 1.952695 1.604742
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 11 2.297016 1.859923 2.603725 2.351421 2.027082 2.004835 2.172207
"ANDHRA PRADESH" "Krishna" 16.61 80.7214 12 2.444685 2.104958 2.152802 2.059896 2.402516 2.272051 2.0992
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 1 2.056532 1.886978 1.878557 2.033217 2.102474 1.978589 2.157366
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 2 2.212771 2.158808 2.061958 2.473369 2.435305 2.272676 2.309306
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 3 2.228094 2.156715 2.145406 2.709743 2.781388 2.305505 2.603585
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 4 2.488699 2.457773 2.239213 2.510946 2.591737 2.673691 2.364792
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 5 2.438172 2.945487 3.199027 2.526551 2.601599 2.514883 2.920263
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 6 3.734309 3.287393 3.806187 3.250664 3.603101 4.160601 3.837503
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 7 4.495672 3.738028 3.756704 2.563712 4.048136 4.704184 3.989675
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 8 3.301626 3.308958 3.112278 3.540206 4.179602 4.823696 2.978726
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 9 3.134211 2.628434 3.065647 2.743994 2.827065 2.477021 2.204995
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 10 2.264361 1.964804 1.912775 2.033182 1.671065 2.17169 1.69776
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 11 2.124653 1.995422 2.382534 2.313824 1.98924 2.006056 2.220546
"ANDHRA PRADESH" "Prakasam" 15.3485 79.5603 12 2.34654 2.072243 1.885468 2.081381 2.116383 2.190996 2.209795
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 1 2.44496 2.590836 2.425676 2.605971 2.501644 2.515942 2.757463
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 2 2.508425 2.762568 2.567573 3.126446 3.197756 2.60129 2.800029
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 3 3.205389 3.237282 2.953511 3.691676 4.10756 3.36654 4.029366
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 4 3.662039 3.821054 3.530229 3.994833 4.279237 4.280625 4.094285
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 5 3.212586 3.671073 4.05303 3.806825 4.215857 3.95336 3.870458
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 6 3.785578 3.46171 3.949253 3.267265 3.760816 3.631304 3.623147
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 7 4.028875 3.644278 3.422719 2.675529 3.510783 4.426352 3.740652
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 8 3.309439 3.221068 3.280735 2.928878 3.648352 4.515591 3.001187
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 9 3.065851 2.845231 2.899631 2.802588 3.053627 2.959442 2.436929
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 10 2.54024 2.594199 2.424494 2.607889 2.401534 2.679014 2.344
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 11 2.683003 2.720275 3.157192 3.142681 2.674055 2.672804 2.926601
"ANDHRA PRADESH" "SPS Nellore" 14.2581 79.9193 12 3.434187 2.877907 2.651093 3.038168 2.910573 2.87581 2.851641
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 1 3.073378 3.212418 2.792619 3.054945 2.819027 2.648022 2.986223
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 2 3.036501 3.030879 3.170356 3.00584 3.223879 2.857637 2.92332
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 3 3.2237 3.786842 3.660542 3.183375 4.176651 4.108239 4.844308
"ANDHRA PRADESH" "Srikakulam" 18.2949 83.8938 4 3.600516 5.530527 4.27437 4.589071 4.829042 5.10582 5.711472
end data analysis MATLAB Answers — New Questions
Y double axis required trendlines
x = [1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020];
y1 = [18.1969 15.834 16.5986 3.1579 10.9866 8.2062 8.9229 9.6429 6.4604 14.805 9.1178 0.49 2.9925 8.7875 5.7404 5.365 8.32 13.025 10.9654 3.26 8.975 4.795 0.97 32.3175 11.1025 0.65 9.5425 12.115 9.8975 21.875 16.6925];
y2 = [17.360463 15.30933 12.563672 2.174533 8.407282 5.828774 4.764783 5.524783 3.644908 15.515 7.022406 0.1715 1.168625 4.729125 3.232158 2.149 6.37575 12.0585 7.024658 1.355 5.591 3.088 0.396 25.004125 8.130375 0.2355 5.040375 7.95375 5.477375 18.4155 16.567625];
figure(‘Color’,’w’)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
ylabel(hAx(1),’ACE (knot^2)’) % left y-axis
ylabel(hAx(2),’PDI (knot^3)’) % right y-axis
%grid onx = [1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020];
y1 = [18.1969 15.834 16.5986 3.1579 10.9866 8.2062 8.9229 9.6429 6.4604 14.805 9.1178 0.49 2.9925 8.7875 5.7404 5.365 8.32 13.025 10.9654 3.26 8.975 4.795 0.97 32.3175 11.1025 0.65 9.5425 12.115 9.8975 21.875 16.6925];
y2 = [17.360463 15.30933 12.563672 2.174533 8.407282 5.828774 4.764783 5.524783 3.644908 15.515 7.022406 0.1715 1.168625 4.729125 3.232158 2.149 6.37575 12.0585 7.024658 1.355 5.591 3.088 0.396 25.004125 8.130375 0.2355 5.040375 7.95375 5.477375 18.4155 16.567625];
figure(‘Color’,’w’)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
ylabel(hAx(1),’ACE (knot^2)’) % left y-axis
ylabel(hAx(2),’PDI (knot^3)’) % right y-axis
%grid on x = [1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020];
y1 = [18.1969 15.834 16.5986 3.1579 10.9866 8.2062 8.9229 9.6429 6.4604 14.805 9.1178 0.49 2.9925 8.7875 5.7404 5.365 8.32 13.025 10.9654 3.26 8.975 4.795 0.97 32.3175 11.1025 0.65 9.5425 12.115 9.8975 21.875 16.6925];
y2 = [17.360463 15.30933 12.563672 2.174533 8.407282 5.828774 4.764783 5.524783 3.644908 15.515 7.022406 0.1715 1.168625 4.729125 3.232158 2.149 6.37575 12.0585 7.024658 1.355 5.591 3.088 0.396 25.004125 8.130375 0.2355 5.040375 7.95375 5.477375 18.4155 16.567625];
figure(‘Color’,’w’)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
ylabel(hAx(1),’ACE (knot^2)’) % left y-axis
ylabel(hAx(2),’PDI (knot^3)’) % right y-axis
%grid on trendline, y double axis MATLAB Answers — New Questions
Is it possible to convert Arduino IDE Code (C++ Code) to MATLAB Code by any means? Or does it have to be done manually?
I’m trying to translate a C++ Code which is used for Soil Moisture Sensor and Raindrop Sensor to a MATLAB Code. I was hoping to convert the C++ Code to a MATLAB Code through faster means since I have no knowledge in C++ Coding. Following is the code.
const int capteur_D = 4;
const int capteur_A = A0;
int val_analogique;
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
pinMode(capteur_D, INPUT);
pinMode(capteur_A, INPUT);
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
delay(250);
if(digitalRead(capteur_D) == LOW)
{
Serial.println("Digital value : wet");
delay(10);
}
else
{
Serial.println("Digital value : dry");
delay(10);
}
val_analogique=analogRead(capteur_A);
Serial.print("Analog value : ");
Serial.println(val_analogique);
Serial.println("");
delay(1000);
}I’m trying to translate a C++ Code which is used for Soil Moisture Sensor and Raindrop Sensor to a MATLAB Code. I was hoping to convert the C++ Code to a MATLAB Code through faster means since I have no knowledge in C++ Coding. Following is the code.
const int capteur_D = 4;
const int capteur_A = A0;
int val_analogique;
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
pinMode(capteur_D, INPUT);
pinMode(capteur_A, INPUT);
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
delay(250);
if(digitalRead(capteur_D) == LOW)
{
Serial.println("Digital value : wet");
delay(10);
}
else
{
Serial.println("Digital value : dry");
delay(10);
}
val_analogique=analogRead(capteur_A);
Serial.print("Analog value : ");
Serial.println(val_analogique);
Serial.println("");
delay(1000);
} I’m trying to translate a C++ Code which is used for Soil Moisture Sensor and Raindrop Sensor to a MATLAB Code. I was hoping to convert the C++ Code to a MATLAB Code through faster means since I have no knowledge in C++ Coding. Following is the code.
const int capteur_D = 4;
const int capteur_A = A0;
int val_analogique;
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
pinMode(capteur_D, INPUT);
pinMode(capteur_A, INPUT);
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
delay(250);
if(digitalRead(capteur_D) == LOW)
{
Serial.println("Digital value : wet");
delay(10);
}
else
{
Serial.println("Digital value : dry");
delay(10);
}
val_analogique=analogRead(capteur_A);
Serial.print("Analog value : ");
Serial.println(val_analogique);
Serial.println("");
delay(1000);
} c++, c++ to matlab MATLAB Answers — New Questions
Errors while linking unreal engine to matlab
Unreal Engine: 5.1.1
Matlab Release: R2024a
I am trying to make a custom scene in unreal engine, for that I installed Aerospace Toolbox Unreal ENgine Interface, after installing, when I try to opne the editor using
`editor.open()’
I get following message:
I tried to build it through IDE but it gave me the following error:
I need help resolving this issue.Unreal Engine: 5.1.1
Matlab Release: R2024a
I am trying to make a custom scene in unreal engine, for that I installed Aerospace Toolbox Unreal ENgine Interface, after installing, when I try to opne the editor using
`editor.open()’
I get following message:
I tried to build it through IDE but it gave me the following error:
I need help resolving this issue. Unreal Engine: 5.1.1
Matlab Release: R2024a
I am trying to make a custom scene in unreal engine, for that I installed Aerospace Toolbox Unreal ENgine Interface, after installing, when I try to opne the editor using
`editor.open()’
I get following message:
I tried to build it through IDE but it gave me the following error:
I need help resolving this issue. unrealengine MATLAB Answers — New Questions
Over time reduce an input value linearly with a delay after each decrement, using a Simulink model
I’m trying to create a Simulink model that has an input value that I want to reduce down to zero in a specific time. It must decrease in linear decrements with a delay after each decrement. The initial input value can also be different, but must reduce down to zero in the same time no matter the starting value.
I have tried using a feedback loop to subtract the original value * the time step, but this just results in the output value decreasing to zero immediately.
Are there any specific blocks for this kind fo linear reduction, or is a more complex block system required?
Thanks for the helpI’m trying to create a Simulink model that has an input value that I want to reduce down to zero in a specific time. It must decrease in linear decrements with a delay after each decrement. The initial input value can also be different, but must reduce down to zero in the same time no matter the starting value.
I have tried using a feedback loop to subtract the original value * the time step, but this just results in the output value decreasing to zero immediately.
Are there any specific blocks for this kind fo linear reduction, or is a more complex block system required?
Thanks for the help I’m trying to create a Simulink model that has an input value that I want to reduce down to zero in a specific time. It must decrease in linear decrements with a delay after each decrement. The initial input value can also be different, but must reduce down to zero in the same time no matter the starting value.
I have tried using a feedback loop to subtract the original value * the time step, but this just results in the output value decreasing to zero immediately.
Are there any specific blocks for this kind fo linear reduction, or is a more complex block system required?
Thanks for the help simulink, feedback loop MATLAB Answers — New Questions
YOLOX – training on tiled images and inference on full-size images
Hello everyone. I am trying to train the YOLOX net for cell detection in brightfield. My original images are 2048×2048. I read on matworks that yolox, being anchor-free, can be trained on tiled images and the inference can be done on full-size images. So what I did was tiliing my images in 4 blocks, 1024×1024 each, then size down everything to 512×512 pixels and do the training. Doing the inference on full-size images gives me 0 precision, as well as scaling down the test set to 1024×1024 pixels, which makes the size of the cells I want to detect the same size as they would be in the preprocessed training set. Is there something I am not grasping due to my scarce experience? thank you to whoever will suggest something. ThanksHello everyone. I am trying to train the YOLOX net for cell detection in brightfield. My original images are 2048×2048. I read on matworks that yolox, being anchor-free, can be trained on tiled images and the inference can be done on full-size images. So what I did was tiliing my images in 4 blocks, 1024×1024 each, then size down everything to 512×512 pixels and do the training. Doing the inference on full-size images gives me 0 precision, as well as scaling down the test set to 1024×1024 pixels, which makes the size of the cells I want to detect the same size as they would be in the preprocessed training set. Is there something I am not grasping due to my scarce experience? thank you to whoever will suggest something. Thanks Hello everyone. I am trying to train the YOLOX net for cell detection in brightfield. My original images are 2048×2048. I read on matworks that yolox, being anchor-free, can be trained on tiled images and the inference can be done on full-size images. So what I did was tiliing my images in 4 blocks, 1024×1024 each, then size down everything to 512×512 pixels and do the training. Doing the inference on full-size images gives me 0 precision, as well as scaling down the test set to 1024×1024 pixels, which makes the size of the cells I want to detect the same size as they would be in the preprocessed training set. Is there something I am not grasping due to my scarce experience? thank you to whoever will suggest something. Thanks yolo, deep learning, detection, machine learning, image processing, computer vision MATLAB Answers — New Questions
error when using lsqnonlin to function containing fzero function
I want to use lsqnonlin analysis to fit a model to two sets of data and obtain values of 4 variables. The function i created contains fzero function which only allows scalar values and i finally got the error ‘operands to the || and && operators ust be convertible to logical scalar values. ‘ So is there any other method that can replace lsqnonlin to solve my problem? Or any corrections, changes to be made in my code to solve this with lsqnonlin? Thanks! Here’s my function file and code.
function Result = myfunc1(a,p,G,m,fraction)
totalconcentration = 0.0000291;
n = 2;
K = exp(-((G + m * fraction)./(8.314*298)));
g_lb = 0;
g_ub = 0.9999;
g =[g_lb g_ub];
monomerconcentration = fzero(@denaturationfun,g);
function y = denaturationfun(x)
y = a.^(-1).*(((a.*x).^(n+1)).*(n.*a.*x-n-1)/((a.*x-1).^2)+a.*x/((a.*x-1).^2))-a.^(n-1).*((x^(n+1)).*(n.*x-n-1)/((x-1).^2))-K.*totalconcentration;
end
Result = p * (1- (monomerconcentration / ( K * totalconcentration )));
end
clc;
clear;
close all;
fractiondata = [0.1505 0.1546 0.1587 0.1628 0.1668 0.1708 0.1748 0.1787 0.1825 0.1864 0.1902 0.194 0.1977 0.2014 0.205 0.2087 0.2123];
DegreeofAggdata = [1 0.9087 0.8658 0.83453 0.79569 0.67979 0.62031 0.53043 0.39722 0.25888 0.15171 0.04759 0.00109 3.20E-04 0.00144 7.77E-04 0];
fun = @(x)DegreeofAggdata – myfunc1(x(1),x(2),x(3),x(4),fractiondata);
x0 = [0.01,0.9,-50000,100000];
lb = [0.00001,0.9,-100000,20000];
ub = [1,1.1,-10000,130000];
x = lsqnonlin(fun,x0,lb,ub);I want to use lsqnonlin analysis to fit a model to two sets of data and obtain values of 4 variables. The function i created contains fzero function which only allows scalar values and i finally got the error ‘operands to the || and && operators ust be convertible to logical scalar values. ‘ So is there any other method that can replace lsqnonlin to solve my problem? Or any corrections, changes to be made in my code to solve this with lsqnonlin? Thanks! Here’s my function file and code.
function Result = myfunc1(a,p,G,m,fraction)
totalconcentration = 0.0000291;
n = 2;
K = exp(-((G + m * fraction)./(8.314*298)));
g_lb = 0;
g_ub = 0.9999;
g =[g_lb g_ub];
monomerconcentration = fzero(@denaturationfun,g);
function y = denaturationfun(x)
y = a.^(-1).*(((a.*x).^(n+1)).*(n.*a.*x-n-1)/((a.*x-1).^2)+a.*x/((a.*x-1).^2))-a.^(n-1).*((x^(n+1)).*(n.*x-n-1)/((x-1).^2))-K.*totalconcentration;
end
Result = p * (1- (monomerconcentration / ( K * totalconcentration )));
end
clc;
clear;
close all;
fractiondata = [0.1505 0.1546 0.1587 0.1628 0.1668 0.1708 0.1748 0.1787 0.1825 0.1864 0.1902 0.194 0.1977 0.2014 0.205 0.2087 0.2123];
DegreeofAggdata = [1 0.9087 0.8658 0.83453 0.79569 0.67979 0.62031 0.53043 0.39722 0.25888 0.15171 0.04759 0.00109 3.20E-04 0.00144 7.77E-04 0];
fun = @(x)DegreeofAggdata – myfunc1(x(1),x(2),x(3),x(4),fractiondata);
x0 = [0.01,0.9,-50000,100000];
lb = [0.00001,0.9,-100000,20000];
ub = [1,1.1,-10000,130000];
x = lsqnonlin(fun,x0,lb,ub); I want to use lsqnonlin analysis to fit a model to two sets of data and obtain values of 4 variables. The function i created contains fzero function which only allows scalar values and i finally got the error ‘operands to the || and && operators ust be convertible to logical scalar values. ‘ So is there any other method that can replace lsqnonlin to solve my problem? Or any corrections, changes to be made in my code to solve this with lsqnonlin? Thanks! Here’s my function file and code.
function Result = myfunc1(a,p,G,m,fraction)
totalconcentration = 0.0000291;
n = 2;
K = exp(-((G + m * fraction)./(8.314*298)));
g_lb = 0;
g_ub = 0.9999;
g =[g_lb g_ub];
monomerconcentration = fzero(@denaturationfun,g);
function y = denaturationfun(x)
y = a.^(-1).*(((a.*x).^(n+1)).*(n.*a.*x-n-1)/((a.*x-1).^2)+a.*x/((a.*x-1).^2))-a.^(n-1).*((x^(n+1)).*(n.*x-n-1)/((x-1).^2))-K.*totalconcentration;
end
Result = p * (1- (monomerconcentration / ( K * totalconcentration )));
end
clc;
clear;
close all;
fractiondata = [0.1505 0.1546 0.1587 0.1628 0.1668 0.1708 0.1748 0.1787 0.1825 0.1864 0.1902 0.194 0.1977 0.2014 0.205 0.2087 0.2123];
DegreeofAggdata = [1 0.9087 0.8658 0.83453 0.79569 0.67979 0.62031 0.53043 0.39722 0.25888 0.15171 0.04759 0.00109 3.20E-04 0.00144 7.77E-04 0];
fun = @(x)DegreeofAggdata – myfunc1(x(1),x(2),x(3),x(4),fractiondata);
x0 = [0.01,0.9,-50000,100000];
lb = [0.00001,0.9,-100000,20000];
ub = [1,1.1,-10000,130000];
x = lsqnonlin(fun,x0,lb,ub); matlab, lsqnonlin, fzero, fit model MATLAB Answers — New Questions
Why does findobj behave different in windows than in unix systems?
Hello,
I am facing something rather curious, I am noticing a behaviour different on Matlab function findobj in Windows(10/11) or Unix ( ubuntu 22).
My issue roots to the search of figures by name, in windows I use the function like this
figHandle = findobj(groot,’Name’,figName);
so providing the figName finds the figure as expected, but running same command under Matlab unix version it returns empty figHandle. I use the Matlab unix version in my CI environment where I found the issue.
Does it rely on lower OS functions that do not behave the same? Can I overcome this issue?
Thanks in advance,
RegardsHello,
I am facing something rather curious, I am noticing a behaviour different on Matlab function findobj in Windows(10/11) or Unix ( ubuntu 22).
My issue roots to the search of figures by name, in windows I use the function like this
figHandle = findobj(groot,’Name’,figName);
so providing the figName finds the figure as expected, but running same command under Matlab unix version it returns empty figHandle. I use the Matlab unix version in my CI environment where I found the issue.
Does it rely on lower OS functions that do not behave the same? Can I overcome this issue?
Thanks in advance,
Regards Hello,
I am facing something rather curious, I am noticing a behaviour different on Matlab function findobj in Windows(10/11) or Unix ( ubuntu 22).
My issue roots to the search of figures by name, in windows I use the function like this
figHandle = findobj(groot,’Name’,figName);
so providing the figName finds the figure as expected, but running same command under Matlab unix version it returns empty figHandle. I use the Matlab unix version in my CI environment where I found the issue.
Does it rely on lower OS functions that do not behave the same? Can I overcome this issue?
Thanks in advance,
Regards findobj MATLAB Answers — New Questions
How to use LSTM to solve seq2seq problem in MATLAB?
I’m struggling with a seq2seq problem. That is: input 200 past values and use LSTM network to predict next 10 values at one time(winthout using closed loop forecasting).And I tried writing the code as shown below. But it will report an error: Invalid training data. For regression tasks, responses must be a vector, a matrix, or a 4-D array of real numeric responses. Responses must not contain NaNs.
inputSize = 5; % Number of input features
numTimeSteps = 200; % Number of time steps
numSamples = 100; % Number of samples
% Create random input data, a cell array of size [5, 200]
X = cell(numSamples, 1);
for i = 1:numSamples
X{i} = rand(inputSize, numTimeSteps);
end
outputSize = 1; % Number of output features for each time step
outputTimeSteps = 10; % Number of output time steps
numSamples = 100; % Number of samples
% Create random output data, a cell array of size [1, 10]
Y = cell(numSamples, 1);
for i = 1:numSamples
Y{i} = rand(outputSize, outputTimeSteps);
end
numHiddenUnits1 = 128; % Number of hidden units in the first LSTM layer
numHiddenUnits2 = 64; % Number of hidden units in the second LSTM layer
outputSize = 1; % Number of output features
layers = [
sequenceInputLayer(inputSize) % Input layer, number of input features is 5
lstmLayer(numHiddenUnits1, ‘OutputMode’, ‘last’) % First LSTM layer, outputs the last time step
fullyConnectedLayer(numHiddenUnits2) % Fully connected layer, transforms the input dimensions for the second LSTM layer
functionLayer(@(X) repmat(X, [1, outputTimeSteps]), ‘Name’, ‘replicate10’) % Expand the output of the last time step to 10 time steps
lstmLayer(numHiddenUnits2, ‘OutputMode’, ‘sequence’) % Second LSTM layer, outputs a sequence of 10 time steps
fullyConnectedLayer(outputSize) % Fully connected layer, number of output features is 1
regressionLayer]; % Regression layer, used for regression tasks
% Training options
options = trainingOptions(‘adam’, …
‘MaxEpochs’, 50, …
‘MiniBatchSize’, 32, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, false);
% Train the network
net = trainNetwork(X, Y, layers, options);
Now I have two questions:
(1) What data format should be used for the input and output of the model during training? Cell arrays or 3D arrays?
(2) How to control the time expansion steps of the input and output for each layer (input layer, LSTM layer, fully connected layer) in an LSTM network?I’m struggling with a seq2seq problem. That is: input 200 past values and use LSTM network to predict next 10 values at one time(winthout using closed loop forecasting).And I tried writing the code as shown below. But it will report an error: Invalid training data. For regression tasks, responses must be a vector, a matrix, or a 4-D array of real numeric responses. Responses must not contain NaNs.
inputSize = 5; % Number of input features
numTimeSteps = 200; % Number of time steps
numSamples = 100; % Number of samples
% Create random input data, a cell array of size [5, 200]
X = cell(numSamples, 1);
for i = 1:numSamples
X{i} = rand(inputSize, numTimeSteps);
end
outputSize = 1; % Number of output features for each time step
outputTimeSteps = 10; % Number of output time steps
numSamples = 100; % Number of samples
% Create random output data, a cell array of size [1, 10]
Y = cell(numSamples, 1);
for i = 1:numSamples
Y{i} = rand(outputSize, outputTimeSteps);
end
numHiddenUnits1 = 128; % Number of hidden units in the first LSTM layer
numHiddenUnits2 = 64; % Number of hidden units in the second LSTM layer
outputSize = 1; % Number of output features
layers = [
sequenceInputLayer(inputSize) % Input layer, number of input features is 5
lstmLayer(numHiddenUnits1, ‘OutputMode’, ‘last’) % First LSTM layer, outputs the last time step
fullyConnectedLayer(numHiddenUnits2) % Fully connected layer, transforms the input dimensions for the second LSTM layer
functionLayer(@(X) repmat(X, [1, outputTimeSteps]), ‘Name’, ‘replicate10’) % Expand the output of the last time step to 10 time steps
lstmLayer(numHiddenUnits2, ‘OutputMode’, ‘sequence’) % Second LSTM layer, outputs a sequence of 10 time steps
fullyConnectedLayer(outputSize) % Fully connected layer, number of output features is 1
regressionLayer]; % Regression layer, used for regression tasks
% Training options
options = trainingOptions(‘adam’, …
‘MaxEpochs’, 50, …
‘MiniBatchSize’, 32, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, false);
% Train the network
net = trainNetwork(X, Y, layers, options);
Now I have two questions:
(1) What data format should be used for the input and output of the model during training? Cell arrays or 3D arrays?
(2) How to control the time expansion steps of the input and output for each layer (input layer, LSTM layer, fully connected layer) in an LSTM network? I’m struggling with a seq2seq problem. That is: input 200 past values and use LSTM network to predict next 10 values at one time(winthout using closed loop forecasting).And I tried writing the code as shown below. But it will report an error: Invalid training data. For regression tasks, responses must be a vector, a matrix, or a 4-D array of real numeric responses. Responses must not contain NaNs.
inputSize = 5; % Number of input features
numTimeSteps = 200; % Number of time steps
numSamples = 100; % Number of samples
% Create random input data, a cell array of size [5, 200]
X = cell(numSamples, 1);
for i = 1:numSamples
X{i} = rand(inputSize, numTimeSteps);
end
outputSize = 1; % Number of output features for each time step
outputTimeSteps = 10; % Number of output time steps
numSamples = 100; % Number of samples
% Create random output data, a cell array of size [1, 10]
Y = cell(numSamples, 1);
for i = 1:numSamples
Y{i} = rand(outputSize, outputTimeSteps);
end
numHiddenUnits1 = 128; % Number of hidden units in the first LSTM layer
numHiddenUnits2 = 64; % Number of hidden units in the second LSTM layer
outputSize = 1; % Number of output features
layers = [
sequenceInputLayer(inputSize) % Input layer, number of input features is 5
lstmLayer(numHiddenUnits1, ‘OutputMode’, ‘last’) % First LSTM layer, outputs the last time step
fullyConnectedLayer(numHiddenUnits2) % Fully connected layer, transforms the input dimensions for the second LSTM layer
functionLayer(@(X) repmat(X, [1, outputTimeSteps]), ‘Name’, ‘replicate10’) % Expand the output of the last time step to 10 time steps
lstmLayer(numHiddenUnits2, ‘OutputMode’, ‘sequence’) % Second LSTM layer, outputs a sequence of 10 time steps
fullyConnectedLayer(outputSize) % Fully connected layer, number of output features is 1
regressionLayer]; % Regression layer, used for regression tasks
% Training options
options = trainingOptions(‘adam’, …
‘MaxEpochs’, 50, …
‘MiniBatchSize’, 32, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, false);
% Train the network
net = trainNetwork(X, Y, layers, options);
Now I have two questions:
(1) What data format should be used for the input and output of the model during training? Cell arrays or 3D arrays?
(2) How to control the time expansion steps of the input and output for each layer (input layer, LSTM layer, fully connected layer) in an LSTM network? lstm, seq2seq, multi step MATLAB Answers — New Questions
Newton method for solving a nonlinear system of equations!
Hello,
I am trying to write a function that solves a non linear system of equations. In my exercise I have 2,3 and 4 dimensional equation system. I am not allowed to use fsolve function. I also have a function called "Score4" which is suppose to calculate the score of my function ( should be around 1 if the code that I wrote is correct).
Below you will find the score and the code that I wrote.
Thank you in advance for your time.
function [score,error,details] = Score4()
%% Parameter
% 2 dimensional equation system
A{1} = @(x)[4*cos(x(1)),2*cos(x(1)+x(2));
5*sin(x(1)),1*sin(x(1)+x(2))];
x0{1} = [0,0]’;
y{1} = [2,3]’;
y0{1} = [-1,1]’;
% 3 dimensional equation system
A{2} = @(x)[1,0,0;0,cos(x(1)),-sin(x(2));0,sin(x(2))^2,cos(x(1))];
x0{2} = [0;0];
y0{2} = [1;2;3];
y{2} = [1;0;1];
% 4 dimensional transformation matrix with 5d input
A{3} = @(x)[cos(x(1)),sin(x(1)),0,-x(3);
-sin(x(1))*cos(x(4)),cos(x(1))*cos(x(4)),sin(x(4))*sin(x(5)),-x(2)*sin(x(4))*cos(x(5));
sin(x(4))*sin(x(1)),-cos(x(1))*sin(x(4)),cos(x(4))*sin(x(5)),-x(2)*cos(x(4))*cos(x(5));
0,0,0,1];
x0{3} = [0;0;0;0;0];
y0{3} = [1;3;2;1];
y{3} = [1;2;-1;1];
%% Score Berechnung
score = 0;
error = ”;
details = struct();
try
% Iteration ueber testcases
for i = 1:3
% Aufstellen des nullstellenproblems
RootProblem = @(z) A{i}(z)*y0{i}-y{i};
T = 0;
% Mitteln ueber Zeit
timer = tic();
for j = 1:10
x = nlinSolve(RootProblem,x0{i});
end
T = toc(timer)/10;
output = A{i}(x)*y0{i}-y{i};
Err = norm(output);
Sc = (Err+0.01)*(T+0.5);
score = score+Sc;
details.([‘time’,num2str(i)]) = T;
details.([‘error’,num2str(i)]) = Err;
end
score = 0.017 / score;
catch err
score = 0;
error = err.message;
end
end
To solve this problem I was thinking to use Newton method but I am having a lot of problems. Can someone give me some suggestions how to improve my code and what am I doing wrong. My code is as follows:
function x = nlinSolve (g,x0)
select = @(g,r,c) g(r,c);
G1 = @(x)select(g(x), 1, 1); % selecting the first row of g(x)
G2 = @(x)select(g(x), 2, 1); % selecting the second row
G3 = @(x)select(g(x), 3, 1);
G4 = @(x)select(g(x), 4, 1);
G5 = @(x)select(g(x), 5, 1);
x = x0; % x0 initial guess which is given in the score function
for m=1:10
%calculating Jacobian
for k=1:numel(x)
for n =1: numel(x)
Jakobian(k,n)= Derivative(eval([‘G’,num2str(k)]),x,x(n),n);
end
end
x = x-inv(Jakobian)*g(x); % Newton formula to find roots
end
end
function J = Derivative(G,x,xm,m)
% the funciton that calculates the derivative using numerical method
e = 0.0001;
x1=x;
x2=x;
x1(m) = xm;
x2(m) = xm+e;
J = (G(x2)-G(x1))/e;
end
Now this code is clearly not working, I am messing up something. Also the score should be around 1 at the end.
If anyone can help me that would be more than appritiated.Hello,
I am trying to write a function that solves a non linear system of equations. In my exercise I have 2,3 and 4 dimensional equation system. I am not allowed to use fsolve function. I also have a function called "Score4" which is suppose to calculate the score of my function ( should be around 1 if the code that I wrote is correct).
Below you will find the score and the code that I wrote.
Thank you in advance for your time.
function [score,error,details] = Score4()
%% Parameter
% 2 dimensional equation system
A{1} = @(x)[4*cos(x(1)),2*cos(x(1)+x(2));
5*sin(x(1)),1*sin(x(1)+x(2))];
x0{1} = [0,0]’;
y{1} = [2,3]’;
y0{1} = [-1,1]’;
% 3 dimensional equation system
A{2} = @(x)[1,0,0;0,cos(x(1)),-sin(x(2));0,sin(x(2))^2,cos(x(1))];
x0{2} = [0;0];
y0{2} = [1;2;3];
y{2} = [1;0;1];
% 4 dimensional transformation matrix with 5d input
A{3} = @(x)[cos(x(1)),sin(x(1)),0,-x(3);
-sin(x(1))*cos(x(4)),cos(x(1))*cos(x(4)),sin(x(4))*sin(x(5)),-x(2)*sin(x(4))*cos(x(5));
sin(x(4))*sin(x(1)),-cos(x(1))*sin(x(4)),cos(x(4))*sin(x(5)),-x(2)*cos(x(4))*cos(x(5));
0,0,0,1];
x0{3} = [0;0;0;0;0];
y0{3} = [1;3;2;1];
y{3} = [1;2;-1;1];
%% Score Berechnung
score = 0;
error = ”;
details = struct();
try
% Iteration ueber testcases
for i = 1:3
% Aufstellen des nullstellenproblems
RootProblem = @(z) A{i}(z)*y0{i}-y{i};
T = 0;
% Mitteln ueber Zeit
timer = tic();
for j = 1:10
x = nlinSolve(RootProblem,x0{i});
end
T = toc(timer)/10;
output = A{i}(x)*y0{i}-y{i};
Err = norm(output);
Sc = (Err+0.01)*(T+0.5);
score = score+Sc;
details.([‘time’,num2str(i)]) = T;
details.([‘error’,num2str(i)]) = Err;
end
score = 0.017 / score;
catch err
score = 0;
error = err.message;
end
end
To solve this problem I was thinking to use Newton method but I am having a lot of problems. Can someone give me some suggestions how to improve my code and what am I doing wrong. My code is as follows:
function x = nlinSolve (g,x0)
select = @(g,r,c) g(r,c);
G1 = @(x)select(g(x), 1, 1); % selecting the first row of g(x)
G2 = @(x)select(g(x), 2, 1); % selecting the second row
G3 = @(x)select(g(x), 3, 1);
G4 = @(x)select(g(x), 4, 1);
G5 = @(x)select(g(x), 5, 1);
x = x0; % x0 initial guess which is given in the score function
for m=1:10
%calculating Jacobian
for k=1:numel(x)
for n =1: numel(x)
Jakobian(k,n)= Derivative(eval([‘G’,num2str(k)]),x,x(n),n);
end
end
x = x-inv(Jakobian)*g(x); % Newton formula to find roots
end
end
function J = Derivative(G,x,xm,m)
% the funciton that calculates the derivative using numerical method
e = 0.0001;
x1=x;
x2=x;
x1(m) = xm;
x2(m) = xm+e;
J = (G(x2)-G(x1))/e;
end
Now this code is clearly not working, I am messing up something. Also the score should be around 1 at the end.
If anyone can help me that would be more than appritiated. Hello,
I am trying to write a function that solves a non linear system of equations. In my exercise I have 2,3 and 4 dimensional equation system. I am not allowed to use fsolve function. I also have a function called "Score4" which is suppose to calculate the score of my function ( should be around 1 if the code that I wrote is correct).
Below you will find the score and the code that I wrote.
Thank you in advance for your time.
function [score,error,details] = Score4()
%% Parameter
% 2 dimensional equation system
A{1} = @(x)[4*cos(x(1)),2*cos(x(1)+x(2));
5*sin(x(1)),1*sin(x(1)+x(2))];
x0{1} = [0,0]’;
y{1} = [2,3]’;
y0{1} = [-1,1]’;
% 3 dimensional equation system
A{2} = @(x)[1,0,0;0,cos(x(1)),-sin(x(2));0,sin(x(2))^2,cos(x(1))];
x0{2} = [0;0];
y0{2} = [1;2;3];
y{2} = [1;0;1];
% 4 dimensional transformation matrix with 5d input
A{3} = @(x)[cos(x(1)),sin(x(1)),0,-x(3);
-sin(x(1))*cos(x(4)),cos(x(1))*cos(x(4)),sin(x(4))*sin(x(5)),-x(2)*sin(x(4))*cos(x(5));
sin(x(4))*sin(x(1)),-cos(x(1))*sin(x(4)),cos(x(4))*sin(x(5)),-x(2)*cos(x(4))*cos(x(5));
0,0,0,1];
x0{3} = [0;0;0;0;0];
y0{3} = [1;3;2;1];
y{3} = [1;2;-1;1];
%% Score Berechnung
score = 0;
error = ”;
details = struct();
try
% Iteration ueber testcases
for i = 1:3
% Aufstellen des nullstellenproblems
RootProblem = @(z) A{i}(z)*y0{i}-y{i};
T = 0;
% Mitteln ueber Zeit
timer = tic();
for j = 1:10
x = nlinSolve(RootProblem,x0{i});
end
T = toc(timer)/10;
output = A{i}(x)*y0{i}-y{i};
Err = norm(output);
Sc = (Err+0.01)*(T+0.5);
score = score+Sc;
details.([‘time’,num2str(i)]) = T;
details.([‘error’,num2str(i)]) = Err;
end
score = 0.017 / score;
catch err
score = 0;
error = err.message;
end
end
To solve this problem I was thinking to use Newton method but I am having a lot of problems. Can someone give me some suggestions how to improve my code and what am I doing wrong. My code is as follows:
function x = nlinSolve (g,x0)
select = @(g,r,c) g(r,c);
G1 = @(x)select(g(x), 1, 1); % selecting the first row of g(x)
G2 = @(x)select(g(x), 2, 1); % selecting the second row
G3 = @(x)select(g(x), 3, 1);
G4 = @(x)select(g(x), 4, 1);
G5 = @(x)select(g(x), 5, 1);
x = x0; % x0 initial guess which is given in the score function
for m=1:10
%calculating Jacobian
for k=1:numel(x)
for n =1: numel(x)
Jakobian(k,n)= Derivative(eval([‘G’,num2str(k)]),x,x(n),n);
end
end
x = x-inv(Jakobian)*g(x); % Newton formula to find roots
end
end
function J = Derivative(G,x,xm,m)
% the funciton that calculates the derivative using numerical method
e = 0.0001;
x1=x;
x2=x;
x1(m) = xm;
x2(m) = xm+e;
J = (G(x2)-G(x1))/e;
end
Now this code is clearly not working, I am messing up something. Also the score should be around 1 at the end.
If anyone can help me that would be more than appritiated. newton method, nonlinear system of equations, matlab MATLAB Answers — New Questions
I can not use the command‘plot’,what should I do?
error information:
错误使用 plot
查找类 matlab.graphics.chart.primitive.Line 时出错。
But I cannot find the’primitive’ floder. What should I do if I want to use ‘plot’ normally?
ps:The executed program is as follows, which is a simple piece of code.
x = linspace(0,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
title(‘y1=sin(x), y2=cos(x)’)
xlabel(‘X(m)’)
ylabel(‘Y(m)’)error information:
错误使用 plot
查找类 matlab.graphics.chart.primitive.Line 时出错。
But I cannot find the’primitive’ floder. What should I do if I want to use ‘plot’ normally?
ps:The executed program is as follows, which is a simple piece of code.
x = linspace(0,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
title(‘y1=sin(x), y2=cos(x)’)
xlabel(‘X(m)’)
ylabel(‘Y(m)’) error information:
错误使用 plot
查找类 matlab.graphics.chart.primitive.Line 时出错。
But I cannot find the’primitive’ floder. What should I do if I want to use ‘plot’ normally?
ps:The executed program is as follows, which is a simple piece of code.
x = linspace(0,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
title(‘y1=sin(x), y2=cos(x)’)
xlabel(‘X(m)’)
ylabel(‘Y(m)’) plot MATLAB Answers — New Questions
How do I check if a subsystem handle is for a stateflow chart
Hello,
I am trying to write a script that parses my model identifying all subsystems for subsequent processing/modifications via the script.
However, when I have a handle that actually corresponds to a stateflow chart I need to switch to using the stateflow API but how can I easily check if a subsystem handle is a stateflow chart?Hello,
I am trying to write a script that parses my model identifying all subsystems for subsequent processing/modifications via the script.
However, when I have a handle that actually corresponds to a stateflow chart I need to switch to using the stateflow API but how can I easily check if a subsystem handle is a stateflow chart? Hello,
I am trying to write a script that parses my model identifying all subsystems for subsequent processing/modifications via the script.
However, when I have a handle that actually corresponds to a stateflow chart I need to switch to using the stateflow API but how can I easily check if a subsystem handle is a stateflow chart? subsystem handle MATLAB Answers — New Questions