Tag Archives: matlab
How do you open a .xlsx file in excel from matlab.
I am trying to open up a .xlsx file from matlab, and have it open in excel. Right now I am using the command open(filename). This will open the .xlsx in matlab, but i want it opened in excel. The command opentxt(filename) is nice, because it will open a .txt file in notepad. I am looking for something like that for .xls/.xlsx files in excel.I am trying to open up a .xlsx file from matlab, and have it open in excel. Right now I am using the command open(filename). This will open the .xlsx in matlab, but i want it opened in excel. The command opentxt(filename) is nice, because it will open a .txt file in notepad. I am looking for something like that for .xls/.xlsx files in excel. I am trying to open up a .xlsx file from matlab, and have it open in excel. Right now I am using the command open(filename). This will open the .xlsx in matlab, but i want it opened in excel. The command opentxt(filename) is nice, because it will open a .txt file in notepad. I am looking for something like that for .xls/.xlsx files in excel. excel MATLAB Answers — New Questions
With a ribbon plot, how to make the ribbons go along each matrix row instead of each column?
In the ribbon command, the ribbons run along each column of the matrix. The Y vector must be of length = to the number of rows in the matrix. How do I get the ribbons to run along each row of the matrix? I tried many combinations of flipud, fliplr, transpose, etc., and either the axis is going in the wrong direction, or the labels are wrong.
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5]
Y=[0;1;2;3]
ribbon(Y,Z,0.1);
Here the ribbons run in the y direction, but I want them to run in the x direction. Nothing else, e.g., the axis numbering, should change.In the ribbon command, the ribbons run along each column of the matrix. The Y vector must be of length = to the number of rows in the matrix. How do I get the ribbons to run along each row of the matrix? I tried many combinations of flipud, fliplr, transpose, etc., and either the axis is going in the wrong direction, or the labels are wrong.
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5]
Y=[0;1;2;3]
ribbon(Y,Z,0.1);
Here the ribbons run in the y direction, but I want them to run in the x direction. Nothing else, e.g., the axis numbering, should change. In the ribbon command, the ribbons run along each column of the matrix. The Y vector must be of length = to the number of rows in the matrix. How do I get the ribbons to run along each row of the matrix? I tried many combinations of flipud, fliplr, transpose, etc., and either the axis is going in the wrong direction, or the labels are wrong.
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5]
Y=[0;1;2;3]
ribbon(Y,Z,0.1);
Here the ribbons run in the y direction, but I want them to run in the x direction. Nothing else, e.g., the axis numbering, should change. ribbon plot orientation MATLAB Answers — New Questions
Loading satellite TLE data into MATLAB using satellite function
Using TLE data from an online database, MATLAB throws the error "The specified initial conditions will cause the orbit of ‘STARLINK-2438’ to intersect the Earth’s surface." when using this function:
clc
clearvars
close all
format long
G = 3.986004418e14;
% Create a satellite scenario and add ground stations from latitudes and longitudes.
startTime = datetime(2024,7,18,13,00,41);
stopTime = startTime + days(1);
sampleTime = 60*1;
sc = satelliteScenario(startTime,stopTime,sampleTime);
sat = satellite(sc,’test_tle.txt’)
The TLE data in "test_tle.txt" is as follows:
STARLINK-2438
1 48103U 21027M 24199.52200852 .27610719 12343-4 29456-2 0 9995
2 48103 53.0228 234.3624 0004658 334.7729 174.1970 16.36724891183121
when manually importing the values into the function, I dont receive the error:
% Mean Motion Line2 Field 8
semiMajorAxis = (G)^(1/3)/((2*pi*(16.36724891183121)/86400)^(2/3)); % ref : https://space.stackexchange.com/questions/18289/how-to-get-semi-major-axis-from-tle
% Eccentricity Line2 Field 5
eccentricity = 0.0004658;
% Inclination Line2 Field 3
inclination = 53.0228;
% Right Ascension of the asending node Line2 Field 4
rightAscensionOfAscendingNode = 234.3624;
% Argument of perigee Line2 Field 6
argumentOfPeriapsis = 334.7729;
% Mean Anomaly Line2 Field 7
trueAnomaly = 174.1970;
sat = satellite(sc,semiMajorAxis,eccentricity,inclination, …
rightAscensionOfAscendingNode,argumentOfPeriapsis,trueAnomaly);Using TLE data from an online database, MATLAB throws the error "The specified initial conditions will cause the orbit of ‘STARLINK-2438’ to intersect the Earth’s surface." when using this function:
clc
clearvars
close all
format long
G = 3.986004418e14;
% Create a satellite scenario and add ground stations from latitudes and longitudes.
startTime = datetime(2024,7,18,13,00,41);
stopTime = startTime + days(1);
sampleTime = 60*1;
sc = satelliteScenario(startTime,stopTime,sampleTime);
sat = satellite(sc,’test_tle.txt’)
The TLE data in "test_tle.txt" is as follows:
STARLINK-2438
1 48103U 21027M 24199.52200852 .27610719 12343-4 29456-2 0 9995
2 48103 53.0228 234.3624 0004658 334.7729 174.1970 16.36724891183121
when manually importing the values into the function, I dont receive the error:
% Mean Motion Line2 Field 8
semiMajorAxis = (G)^(1/3)/((2*pi*(16.36724891183121)/86400)^(2/3)); % ref : https://space.stackexchange.com/questions/18289/how-to-get-semi-major-axis-from-tle
% Eccentricity Line2 Field 5
eccentricity = 0.0004658;
% Inclination Line2 Field 3
inclination = 53.0228;
% Right Ascension of the asending node Line2 Field 4
rightAscensionOfAscendingNode = 234.3624;
% Argument of perigee Line2 Field 6
argumentOfPeriapsis = 334.7729;
% Mean Anomaly Line2 Field 7
trueAnomaly = 174.1970;
sat = satellite(sc,semiMajorAxis,eccentricity,inclination, …
rightAscensionOfAscendingNode,argumentOfPeriapsis,trueAnomaly); Using TLE data from an online database, MATLAB throws the error "The specified initial conditions will cause the orbit of ‘STARLINK-2438’ to intersect the Earth’s surface." when using this function:
clc
clearvars
close all
format long
G = 3.986004418e14;
% Create a satellite scenario and add ground stations from latitudes and longitudes.
startTime = datetime(2024,7,18,13,00,41);
stopTime = startTime + days(1);
sampleTime = 60*1;
sc = satelliteScenario(startTime,stopTime,sampleTime);
sat = satellite(sc,’test_tle.txt’)
The TLE data in "test_tle.txt" is as follows:
STARLINK-2438
1 48103U 21027M 24199.52200852 .27610719 12343-4 29456-2 0 9995
2 48103 53.0228 234.3624 0004658 334.7729 174.1970 16.36724891183121
when manually importing the values into the function, I dont receive the error:
% Mean Motion Line2 Field 8
semiMajorAxis = (G)^(1/3)/((2*pi*(16.36724891183121)/86400)^(2/3)); % ref : https://space.stackexchange.com/questions/18289/how-to-get-semi-major-axis-from-tle
% Eccentricity Line2 Field 5
eccentricity = 0.0004658;
% Inclination Line2 Field 3
inclination = 53.0228;
% Right Ascension of the asending node Line2 Field 4
rightAscensionOfAscendingNode = 234.3624;
% Argument of perigee Line2 Field 6
argumentOfPeriapsis = 334.7729;
% Mean Anomaly Line2 Field 7
trueAnomaly = 174.1970;
sat = satellite(sc,semiMajorAxis,eccentricity,inclination, …
rightAscensionOfAscendingNode,argumentOfPeriapsis,trueAnomaly); satellite, tle MATLAB Answers — New Questions
How store evolution of x over the iterations of lsqnonlin?
Hi,
I’m solving a nonlinear system of equations with lsqnonlin and want to save the evolution of values of X.
The ouput of the system is defined by a function file ‘error.m’, which takes X with size 4×1 and returns a vector of residuals with size 8×1.
I run a script with the structure below that sets the some fixed parameters for error.m, then calls the lsqnonlin solver and error.m for n cases.
clear all,clc,close all
load measure;
%initialization: set some constant inputs for ‘error.m’ and options for the
%solver
% solve nCases
for i=1:nCases
inputs.measured=measure(i);
X=lsqnonlin(@(x)error(inputs,x),x0,lb,ub,options)
save X X;
end
I want to store the values of X over the iterations, not only the solution. There are these examples in Optimization Solver Output Functions, but they use nested functions and I don’t know how to adapt them to my script structure.
function stop = myoutput(x,optimvalues,state);
stop = false;
if isequal(state,’iter’)
history = [history; x];
end
end
How will the output function ‘myoutput’ access the variable X inside the lsqnonlin?
I’ve tried to write the myoutput at the end of the main script, predefined history = [ ] in the for loop i=1:nCases and set options = optimset(‘OutputFcn’, @myoutput);
However, the function ‘myoutput’ doesn’t find th ehistory variable to append. Why is that happening?Hi,
I’m solving a nonlinear system of equations with lsqnonlin and want to save the evolution of values of X.
The ouput of the system is defined by a function file ‘error.m’, which takes X with size 4×1 and returns a vector of residuals with size 8×1.
I run a script with the structure below that sets the some fixed parameters for error.m, then calls the lsqnonlin solver and error.m for n cases.
clear all,clc,close all
load measure;
%initialization: set some constant inputs for ‘error.m’ and options for the
%solver
% solve nCases
for i=1:nCases
inputs.measured=measure(i);
X=lsqnonlin(@(x)error(inputs,x),x0,lb,ub,options)
save X X;
end
I want to store the values of X over the iterations, not only the solution. There are these examples in Optimization Solver Output Functions, but they use nested functions and I don’t know how to adapt them to my script structure.
function stop = myoutput(x,optimvalues,state);
stop = false;
if isequal(state,’iter’)
history = [history; x];
end
end
How will the output function ‘myoutput’ access the variable X inside the lsqnonlin?
I’ve tried to write the myoutput at the end of the main script, predefined history = [ ] in the for loop i=1:nCases and set options = optimset(‘OutputFcn’, @myoutput);
However, the function ‘myoutput’ doesn’t find th ehistory variable to append. Why is that happening? Hi,
I’m solving a nonlinear system of equations with lsqnonlin and want to save the evolution of values of X.
The ouput of the system is defined by a function file ‘error.m’, which takes X with size 4×1 and returns a vector of residuals with size 8×1.
I run a script with the structure below that sets the some fixed parameters for error.m, then calls the lsqnonlin solver and error.m for n cases.
clear all,clc,close all
load measure;
%initialization: set some constant inputs for ‘error.m’ and options for the
%solver
% solve nCases
for i=1:nCases
inputs.measured=measure(i);
X=lsqnonlin(@(x)error(inputs,x),x0,lb,ub,options)
save X X;
end
I want to store the values of X over the iterations, not only the solution. There are these examples in Optimization Solver Output Functions, but they use nested functions and I don’t know how to adapt them to my script structure.
function stop = myoutput(x,optimvalues,state);
stop = false;
if isequal(state,’iter’)
history = [history; x];
end
end
How will the output function ‘myoutput’ access the variable X inside the lsqnonlin?
I’ve tried to write the myoutput at the end of the main script, predefined history = [ ] in the for loop i=1:nCases and set options = optimset(‘OutputFcn’, @myoutput);
However, the function ‘myoutput’ doesn’t find th ehistory variable to append. Why is that happening? lsqnonlin, output, iteration, optimization MATLAB Answers — New Questions
How to verify/debug LDAP authentication?
I have enabled LDAP authentication for my MATLAB Web App Server. The server can start successfully but I couldn’t log in. What is wrong?I have enabled LDAP authentication for my MATLAB Web App Server. The server can start successfully but I couldn’t log in. What is wrong? I have enabled LDAP authentication for my MATLAB Web App Server. The server can start successfully but I couldn’t log in. What is wrong? MATLAB Answers — New Questions
optimizing neural network with NSGA-II
hello
I have a neural network structure of my data and I want to do a multiobjective optimization for example with NSGA-II. How could I connect my ANN to NSGA-II?
I tried the next code:
[x_ga1,fval_ga1,~,gaoutput1] = gamultiobj(fun,nvar,A,b,Aeq,beq,lb,ub,opts_ga);
where "fun" is my ANN function. but It makes an error!!hello
I have a neural network structure of my data and I want to do a multiobjective optimization for example with NSGA-II. How could I connect my ANN to NSGA-II?
I tried the next code:
[x_ga1,fval_ga1,~,gaoutput1] = gamultiobj(fun,nvar,A,b,Aeq,beq,lb,ub,opts_ga);
where "fun" is my ANN function. but It makes an error!! hello
I have a neural network structure of my data and I want to do a multiobjective optimization for example with NSGA-II. How could I connect my ANN to NSGA-II?
I tried the next code:
[x_ga1,fval_ga1,~,gaoutput1] = gamultiobj(fun,nvar,A,b,Aeq,beq,lb,ub,opts_ga);
where "fun" is my ANN function. but It makes an error!! ann, nsga-ii, multiobjective optimization MATLAB Answers — New Questions
How to loop through a folder and convert all the tiff to png?
So I have a folder full of tiff images, and I want to convert all of them into png. How can I acheive this? I imagine that I need to use a for loop to go through every single image, but I am not sure about the converting part.
Excuse me if this is a simple question, I am quite a rookie of Matlab and I have tried searching online but nothing works.So I have a folder full of tiff images, and I want to convert all of them into png. How can I acheive this? I imagine that I need to use a for loop to go through every single image, but I am not sure about the converting part.
Excuse me if this is a simple question, I am quite a rookie of Matlab and I have tried searching online but nothing works. So I have a folder full of tiff images, and I want to convert all of them into png. How can I acheive this? I imagine that I need to use a for loop to go through every single image, but I am not sure about the converting part.
Excuse me if this is a simple question, I am quite a rookie of Matlab and I have tried searching online but nothing works. image processing, for loop MATLAB Answers — New Questions
What norm StepTolerance uses for multivariable?
I want to define a StepTolerance for the lsqnonlin with ‘trust-region-reflective’algorithm to solve a system of 4 variables, so X has dimension 4×1.
The documention Tolerance Details says that this algorithm uses a Absolute Step Tolerance.
In Tolerances and Stopping Criteria I found this:
"StepTolerance is a lower bound on the size of a step, meaning the norm of (xi – xi+1). If the solver attempts to take a step that is smaller than StepTolerance, the iterations end."
Is this norm the same of function norm, the Euclidean norm?I want to define a StepTolerance for the lsqnonlin with ‘trust-region-reflective’algorithm to solve a system of 4 variables, so X has dimension 4×1.
The documention Tolerance Details says that this algorithm uses a Absolute Step Tolerance.
In Tolerances and Stopping Criteria I found this:
"StepTolerance is a lower bound on the size of a step, meaning the norm of (xi – xi+1). If the solver attempts to take a step that is smaller than StepTolerance, the iterations end."
Is this norm the same of function norm, the Euclidean norm? I want to define a StepTolerance for the lsqnonlin with ‘trust-region-reflective’algorithm to solve a system of 4 variables, so X has dimension 4×1.
The documention Tolerance Details says that this algorithm uses a Absolute Step Tolerance.
In Tolerances and Stopping Criteria I found this:
"StepTolerance is a lower bound on the size of a step, meaning the norm of (xi – xi+1). If the solver attempts to take a step that is smaller than StepTolerance, the iterations end."
Is this norm the same of function norm, the Euclidean norm? lsqnonlin, tolerances, norm MATLAB Answers — New Questions
Trying to create a polynomial formula from xyz chart data where x and y equate to a z value.
I’m trying to create a polynomial formula it could be a 3rd degree to a 6th degree it doesn’t matter how long the formula is I just need it to be accurate and be able to extrapolate as accurately as possibly if the x or y data inputted is off the ends of the chart. Attached is the example of the data that I’m referencing I would like to get a code that I could edit and run myself as I have about 20 similar charts that I want to extrapolate a formula for. I need to be only a temp(y) and a humidity(x) and have the formula spit out (z) and it be accurate based off the chart.I’m trying to create a polynomial formula it could be a 3rd degree to a 6th degree it doesn’t matter how long the formula is I just need it to be accurate and be able to extrapolate as accurately as possibly if the x or y data inputted is off the ends of the chart. Attached is the example of the data that I’m referencing I would like to get a code that I could edit and run myself as I have about 20 similar charts that I want to extrapolate a formula for. I need to be only a temp(y) and a humidity(x) and have the formula spit out (z) and it be accurate based off the chart. I’m trying to create a polynomial formula it could be a 3rd degree to a 6th degree it doesn’t matter how long the formula is I just need it to be accurate and be able to extrapolate as accurately as possibly if the x or y data inputted is off the ends of the chart. Attached is the example of the data that I’m referencing I would like to get a code that I could edit and run myself as I have about 20 similar charts that I want to extrapolate a formula for. I need to be only a temp(y) and a humidity(x) and have the formula spit out (z) and it be accurate based off the chart. interpolation, curve fitting MATLAB Answers — New Questions
Why does my neural net data show up in R2021a but not in R2024a?
I have a 1×1 struct variable that contains 6 fields. Each field is a 1×1 CompactClassificationNeuralNetwork, results from a neural network I use to train on images for image segmentation. When I open this struct in MATLAB R2021a, the struct contains all 6 fields. When I open it in 2024a, the struct contains 6 empty fields. The data doesn’t appear. I have had trouble finding answers online. What might be the issue here?I have a 1×1 struct variable that contains 6 fields. Each field is a 1×1 CompactClassificationNeuralNetwork, results from a neural network I use to train on images for image segmentation. When I open this struct in MATLAB R2021a, the struct contains all 6 fields. When I open it in 2024a, the struct contains 6 empty fields. The data doesn’t appear. I have had trouble finding answers online. What might be the issue here? I have a 1×1 struct variable that contains 6 fields. Each field is a 1×1 CompactClassificationNeuralNetwork, results from a neural network I use to train on images for image segmentation. When I open this struct in MATLAB R2021a, the struct contains all 6 fields. When I open it in 2024a, the struct contains 6 empty fields. The data doesn’t appear. I have had trouble finding answers online. What might be the issue here? neural network, image segmentation MATLAB Answers — New Questions
How can I improve the live streaming performance of Simulation Data Inspector (SDI) when using Simulink Real-Time and Speedgoat?
I use Simulink Real-Time (SLRT) to run simulations on a Speedgoat real-time target and wish to see the live signal data in the Simulation Data Inspector (SDI). To do this, I selected signals for streaming using signal logging badges, the SLRT Explorer, or instrument objects.
However, I noticed that the MATLAB process causes a very high RAM/CPU load on my PC. As a result, the MATLAB GUI can be very slow and laggy. Sometimes, I see noticeable gaps in the data in the SDI, or see that some timesteps are lost when I inspect the ‘logsout’ variable or export data from the SDI. Additionally, I may see the warning below in the Speedgoat system log:
Live Stream overload
Is there any way that I can improve the performance of SDI without reducing my model sample rate?I use Simulink Real-Time (SLRT) to run simulations on a Speedgoat real-time target and wish to see the live signal data in the Simulation Data Inspector (SDI). To do this, I selected signals for streaming using signal logging badges, the SLRT Explorer, or instrument objects.
However, I noticed that the MATLAB process causes a very high RAM/CPU load on my PC. As a result, the MATLAB GUI can be very slow and laggy. Sometimes, I see noticeable gaps in the data in the SDI, or see that some timesteps are lost when I inspect the ‘logsout’ variable or export data from the SDI. Additionally, I may see the warning below in the Speedgoat system log:
Live Stream overload
Is there any way that I can improve the performance of SDI without reducing my model sample rate? I use Simulink Real-Time (SLRT) to run simulations on a Speedgoat real-time target and wish to see the live signal data in the Simulation Data Inspector (SDI). To do this, I selected signals for streaming using signal logging badges, the SLRT Explorer, or instrument objects.
However, I noticed that the MATLAB process causes a very high RAM/CPU load on my PC. As a result, the MATLAB GUI can be very slow and laggy. Sometimes, I see noticeable gaps in the data in the SDI, or see that some timesteps are lost when I inspect the ‘logsout’ variable or export data from the SDI. Additionally, I may see the warning below in the Speedgoat system log:
Live Stream overload
Is there any way that I can improve the performance of SDI without reducing my model sample rate? sdi, real-time, realtime, signal, logging, buffer, delay, slrt, data, gaps, decimation, speedgoat, missing MATLAB Answers — New Questions
Method of Characteristics for Nozzle: Error with syms function
I am trying to create a Method of characteristics Code from JD Andersons book "Modern Compressible Flow with Historical Perspective" using example 11.1. Error arises when I try to obtain the coordinates of the points 2-7; where 7 is the n_div which I have taken.
Code:
clear;
clc;
close all;
%% Initial parameters %%
radian_to_deg = 180/pi;
degree_to_radian = pi/180;
prompt = "Enter a Mach Number ranging from 1.5 to 4: ";
Me = input(prompt);
prompt_1 = "Enter the number of divisions: ";
n_div = input(prompt_1);
%prompt_2 = "Enter the throat radius: ";
%TR = input(prompt_2);
g = 1.4;
mach_angle= [];
theta = [];
theta_a = [];
y=[];
x=[];
v=[];
v_a=[];
dydx_minus = [];
dydx_plus = [];
new_Mach=[];
%% get mach angle
ma_f = @(x) (asind(1/x)) ;
%% get theta_max
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
pm_f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1)));
theta_max = pm_f(Me)/2;
%% extraction of fractional part of theta_max
theta_i = sign(theta_max)*(abs(theta_max) – floor(abs(theta_max)));
%% Storing different values of theta_a
for i = 1:n_div
theta_a(i,1) = theta_i ;
theta_i = theta_i + 3.0;
end
v_a = theta_a;
%% Getting properties of a-1 characteristic line
ya=1;
xa=0;
%theta_a(1,1) = theta_i(1,1);
v_a(1,1) = theta_a(1,1);
%point 1
y(1,1) = 0;
Km_1 = theta_a(1,1) + v_a(1,1);
theta(1,1)= 0.5*(Km_1);
v(1,1) = 0.5*(Km_1);
%% get mach number for v(1,1)
syms x
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(1,1));
f1 = matlabFunction(diff(f(x)));
%NR Method using a while loop
change = 10;
Mguess = 1.1;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(1,1) = Mnew;
mach_angle(1,1) = ma_f(Mnew);
x(1,1) = -ya/tand(theta(1,1)-mach_angle(1,1));
%% rest of points:
for i = 2:n_div
Km = (theta_a(i,1)) + (v_a(i,1));
Kp = theta(i-1,1) – v(i-1,1);
theta(i,1) = 0.5*(Km+Kp);
v(i,1) = 0.5*(Km-Kp);
end
%% Calculating the Unknown Mach Number and corresponding Mach Angle using NR Method
syms x
for i=2:n_div
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(i,1));
f1 = matlabFunction(diff(f(x)));
Mguess = 1.1;
change = 10;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(i,1) = Mnew;
mach_angle(i,1) = ma_f(Mnew);
end
%% slopes and locations of points from 2-7
for i=2:n_div
dydx_minus(i,1) = tand(0.5*(theta(i)+theta(i)) – 0.5*(mach_angle(i)+mach_angle(i)));
dydx_plus(i,1) = tand(0.5*(theta(i) + theta(i-1))) + (0.5*(mach_angle(i) + mach_angle(i-1)));
x(i,1) = (y(i-1,1) – ya – (dydx_plus(i,1)*x(i-1)))/(dydx_minus(i,1) – dydx_plus(i,1));
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
end
%slope and location of wall point 8
slopew1_minus = tand(theta_max);
slopew1_plus = dydx_plus(end,1);
xw = (y(end,1)-ya-(slopew1_plus*x(end,1)))/(slopew1_minus – slopew1_plus);
yw = (slopew1_plus*(xw(1,1)-x(end,1)))+y(end,1);
Error:
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(a_double(i,1)-a_double(i-1))) + y(i-1);
Unable to perform assignment because value of type ‘sym’ is not convertible to ‘double’.
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
Caused by:
Error using mupadengine/feval2char
Unable to convert expression containing symbolic variables into double array. Apply ‘subs’ function
first to substitute values for variables.
Is there any way I can resolve this error? Thank you!I am trying to create a Method of characteristics Code from JD Andersons book "Modern Compressible Flow with Historical Perspective" using example 11.1. Error arises when I try to obtain the coordinates of the points 2-7; where 7 is the n_div which I have taken.
Code:
clear;
clc;
close all;
%% Initial parameters %%
radian_to_deg = 180/pi;
degree_to_radian = pi/180;
prompt = "Enter a Mach Number ranging from 1.5 to 4: ";
Me = input(prompt);
prompt_1 = "Enter the number of divisions: ";
n_div = input(prompt_1);
%prompt_2 = "Enter the throat radius: ";
%TR = input(prompt_2);
g = 1.4;
mach_angle= [];
theta = [];
theta_a = [];
y=[];
x=[];
v=[];
v_a=[];
dydx_minus = [];
dydx_plus = [];
new_Mach=[];
%% get mach angle
ma_f = @(x) (asind(1/x)) ;
%% get theta_max
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
pm_f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1)));
theta_max = pm_f(Me)/2;
%% extraction of fractional part of theta_max
theta_i = sign(theta_max)*(abs(theta_max) – floor(abs(theta_max)));
%% Storing different values of theta_a
for i = 1:n_div
theta_a(i,1) = theta_i ;
theta_i = theta_i + 3.0;
end
v_a = theta_a;
%% Getting properties of a-1 characteristic line
ya=1;
xa=0;
%theta_a(1,1) = theta_i(1,1);
v_a(1,1) = theta_a(1,1);
%point 1
y(1,1) = 0;
Km_1 = theta_a(1,1) + v_a(1,1);
theta(1,1)= 0.5*(Km_1);
v(1,1) = 0.5*(Km_1);
%% get mach number for v(1,1)
syms x
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(1,1));
f1 = matlabFunction(diff(f(x)));
%NR Method using a while loop
change = 10;
Mguess = 1.1;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(1,1) = Mnew;
mach_angle(1,1) = ma_f(Mnew);
x(1,1) = -ya/tand(theta(1,1)-mach_angle(1,1));
%% rest of points:
for i = 2:n_div
Km = (theta_a(i,1)) + (v_a(i,1));
Kp = theta(i-1,1) – v(i-1,1);
theta(i,1) = 0.5*(Km+Kp);
v(i,1) = 0.5*(Km-Kp);
end
%% Calculating the Unknown Mach Number and corresponding Mach Angle using NR Method
syms x
for i=2:n_div
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(i,1));
f1 = matlabFunction(diff(f(x)));
Mguess = 1.1;
change = 10;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(i,1) = Mnew;
mach_angle(i,1) = ma_f(Mnew);
end
%% slopes and locations of points from 2-7
for i=2:n_div
dydx_minus(i,1) = tand(0.5*(theta(i)+theta(i)) – 0.5*(mach_angle(i)+mach_angle(i)));
dydx_plus(i,1) = tand(0.5*(theta(i) + theta(i-1))) + (0.5*(mach_angle(i) + mach_angle(i-1)));
x(i,1) = (y(i-1,1) – ya – (dydx_plus(i,1)*x(i-1)))/(dydx_minus(i,1) – dydx_plus(i,1));
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
end
%slope and location of wall point 8
slopew1_minus = tand(theta_max);
slopew1_plus = dydx_plus(end,1);
xw = (y(end,1)-ya-(slopew1_plus*x(end,1)))/(slopew1_minus – slopew1_plus);
yw = (slopew1_plus*(xw(1,1)-x(end,1)))+y(end,1);
Error:
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(a_double(i,1)-a_double(i-1))) + y(i-1);
Unable to perform assignment because value of type ‘sym’ is not convertible to ‘double’.
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
Caused by:
Error using mupadengine/feval2char
Unable to convert expression containing symbolic variables into double array. Apply ‘subs’ function
first to substitute values for variables.
Is there any way I can resolve this error? Thank you! I am trying to create a Method of characteristics Code from JD Andersons book "Modern Compressible Flow with Historical Perspective" using example 11.1. Error arises when I try to obtain the coordinates of the points 2-7; where 7 is the n_div which I have taken.
Code:
clear;
clc;
close all;
%% Initial parameters %%
radian_to_deg = 180/pi;
degree_to_radian = pi/180;
prompt = "Enter a Mach Number ranging from 1.5 to 4: ";
Me = input(prompt);
prompt_1 = "Enter the number of divisions: ";
n_div = input(prompt_1);
%prompt_2 = "Enter the throat radius: ";
%TR = input(prompt_2);
g = 1.4;
mach_angle= [];
theta = [];
theta_a = [];
y=[];
x=[];
v=[];
v_a=[];
dydx_minus = [];
dydx_plus = [];
new_Mach=[];
%% get mach angle
ma_f = @(x) (asind(1/x)) ;
%% get theta_max
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
pm_f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1)));
theta_max = pm_f(Me)/2;
%% extraction of fractional part of theta_max
theta_i = sign(theta_max)*(abs(theta_max) – floor(abs(theta_max)));
%% Storing different values of theta_a
for i = 1:n_div
theta_a(i,1) = theta_i ;
theta_i = theta_i + 3.0;
end
v_a = theta_a;
%% Getting properties of a-1 characteristic line
ya=1;
xa=0;
%theta_a(1,1) = theta_i(1,1);
v_a(1,1) = theta_a(1,1);
%point 1
y(1,1) = 0;
Km_1 = theta_a(1,1) + v_a(1,1);
theta(1,1)= 0.5*(Km_1);
v(1,1) = 0.5*(Km_1);
%% get mach number for v(1,1)
syms x
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(1,1));
f1 = matlabFunction(diff(f(x)));
%NR Method using a while loop
change = 10;
Mguess = 1.1;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(1,1) = Mnew;
mach_angle(1,1) = ma_f(Mnew);
x(1,1) = -ya/tand(theta(1,1)-mach_angle(1,1));
%% rest of points:
for i = 2:n_div
Km = (theta_a(i,1)) + (v_a(i,1));
Kp = theta(i-1,1) – v(i-1,1);
theta(i,1) = 0.5*(Km+Kp);
v(i,1) = 0.5*(Km-Kp);
end
%% Calculating the Unknown Mach Number and corresponding Mach Angle using NR Method
syms x
for i=2:n_div
f = @(x) (A*atand(sqrt(B*(x^2-1))) – atand(sqrt(x^2-1))-v(i,1));
f1 = matlabFunction(diff(f(x)));
Mguess = 1.1;
change = 10;
while (change>1e-6)
Mnew = Mguess – f(Mguess)/f1(Mguess);
change = abs(Mguess – Mnew);
Mguess = Mnew;
end
new_Mach(i,1) = Mnew;
mach_angle(i,1) = ma_f(Mnew);
end
%% slopes and locations of points from 2-7
for i=2:n_div
dydx_minus(i,1) = tand(0.5*(theta(i)+theta(i)) – 0.5*(mach_angle(i)+mach_angle(i)));
dydx_plus(i,1) = tand(0.5*(theta(i) + theta(i-1))) + (0.5*(mach_angle(i) + mach_angle(i-1)));
x(i,1) = (y(i-1,1) – ya – (dydx_plus(i,1)*x(i-1)))/(dydx_minus(i,1) – dydx_plus(i,1));
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
end
%slope and location of wall point 8
slopew1_minus = tand(theta_max);
slopew1_plus = dydx_plus(end,1);
xw = (y(end,1)-ya-(slopew1_plus*x(end,1)))/(slopew1_minus – slopew1_plus);
yw = (slopew1_plus*(xw(1,1)-x(end,1)))+y(end,1);
Error:
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(a_double(i,1)-a_double(i-1))) + y(i-1);
Unable to perform assignment because value of type ‘sym’ is not convertible to ‘double’.
Error in MOC_prac (line 111)
y(i,1) = (dydx_plus(i,1)*(x(i,1)-x(i-1))) + y(i-1);
Caused by:
Error using mupadengine/feval2char
Unable to convert expression containing symbolic variables into double array. Apply ‘subs’ function
first to substitute values for variables.
Is there any way I can resolve this error? Thank you! #syms, #subs, #double MATLAB Answers — New Questions
How can I make a graph like this for ANOVA 2-Way
I’m trying to obtain this graph from the example here for my ANOVA data: https://www.mathworks.com/matlabcentral/answers/488962-repeated-measures-anova-matlab?s_tid=srchtitle. However, I am having a hard time understanding the code. This is the code I’ve written for my data so far.
clear
clc
table1 = readtable(‘assignment3simple.xlsx’);
table1matrix = table1{:,2:7};
anova2(table1matrix, 2)
figure;
boxplot(table1matrix,{’20°C’, ’30°C’, ’40°C’, ’50°C’, ’60°C’, ’70°C’})
xlabel(‘Operating Temperature’);
ylabel(‘Power Output (w)’);
title(‘Box Plot of Power Output at Different Operating Temperatures’);
I’ve already got the graph for the interaction but getting the individual one is confusing me. Any help would be greatly appreciated. Thank you.
Note: This is the code used for the figure. (I am not using the same data, just trying to understand the code and apply it to mine)
bpdata = [];
for i = 1:max(Q2.PATIENT) %assuming patient numbers are 1:max
bpdata = [bpdata, Q2{Q2.PATIENT==i,3:8},nan(size(unique(Q2.TREAT)))];
end
figure()
boxplot(bpdata)
arrayfun(@xline,7:7:size(bpdata,2))
xlabel(‘6 treatment times across 11 patients’)
ylabel(‘measurement value’)
title(‘Data pooled between treatment factors’)
set(gca,’XTick’, [])
(Courtesy of Adam Danz)I’m trying to obtain this graph from the example here for my ANOVA data: https://www.mathworks.com/matlabcentral/answers/488962-repeated-measures-anova-matlab?s_tid=srchtitle. However, I am having a hard time understanding the code. This is the code I’ve written for my data so far.
clear
clc
table1 = readtable(‘assignment3simple.xlsx’);
table1matrix = table1{:,2:7};
anova2(table1matrix, 2)
figure;
boxplot(table1matrix,{’20°C’, ’30°C’, ’40°C’, ’50°C’, ’60°C’, ’70°C’})
xlabel(‘Operating Temperature’);
ylabel(‘Power Output (w)’);
title(‘Box Plot of Power Output at Different Operating Temperatures’);
I’ve already got the graph for the interaction but getting the individual one is confusing me. Any help would be greatly appreciated. Thank you.
Note: This is the code used for the figure. (I am not using the same data, just trying to understand the code and apply it to mine)
bpdata = [];
for i = 1:max(Q2.PATIENT) %assuming patient numbers are 1:max
bpdata = [bpdata, Q2{Q2.PATIENT==i,3:8},nan(size(unique(Q2.TREAT)))];
end
figure()
boxplot(bpdata)
arrayfun(@xline,7:7:size(bpdata,2))
xlabel(‘6 treatment times across 11 patients’)
ylabel(‘measurement value’)
title(‘Data pooled between treatment factors’)
set(gca,’XTick’, [])
(Courtesy of Adam Danz) I’m trying to obtain this graph from the example here for my ANOVA data: https://www.mathworks.com/matlabcentral/answers/488962-repeated-measures-anova-matlab?s_tid=srchtitle. However, I am having a hard time understanding the code. This is the code I’ve written for my data so far.
clear
clc
table1 = readtable(‘assignment3simple.xlsx’);
table1matrix = table1{:,2:7};
anova2(table1matrix, 2)
figure;
boxplot(table1matrix,{’20°C’, ’30°C’, ’40°C’, ’50°C’, ’60°C’, ’70°C’})
xlabel(‘Operating Temperature’);
ylabel(‘Power Output (w)’);
title(‘Box Plot of Power Output at Different Operating Temperatures’);
I’ve already got the graph for the interaction but getting the individual one is confusing me. Any help would be greatly appreciated. Thank you.
Note: This is the code used for the figure. (I am not using the same data, just trying to understand the code and apply it to mine)
bpdata = [];
for i = 1:max(Q2.PATIENT) %assuming patient numbers are 1:max
bpdata = [bpdata, Q2{Q2.PATIENT==i,3:8},nan(size(unique(Q2.TREAT)))];
end
figure()
boxplot(bpdata)
arrayfun(@xline,7:7:size(bpdata,2))
xlabel(‘6 treatment times across 11 patients’)
ylabel(‘measurement value’)
title(‘Data pooled between treatment factors’)
set(gca,’XTick’, [])
(Courtesy of Adam Danz) anova, statistics, matlab MATLAB Answers — New Questions
When I try to creat FMU, “docker container failed to start” error happened
Hello, all:
I try to create a FMU for Linux in windows system. but after I have met one error when I try to build. see following:
Failed to set up the docker environment for cross-platform compilation because the container could not be retrieved. If the computer does not have internet access, check documentation for manually downloading the docker container.
docker container failed to start
a few weeks ago, I alread successed creat a FMU for Linux in windows system. but I don’t know why this time when I try to build FMU again, one error happened?
can you help me to solve it?
thank you.Hello, all:
I try to create a FMU for Linux in windows system. but after I have met one error when I try to build. see following:
Failed to set up the docker environment for cross-platform compilation because the container could not be retrieved. If the computer does not have internet access, check documentation for manually downloading the docker container.
docker container failed to start
a few weeks ago, I alread successed creat a FMU for Linux in windows system. but I don’t know why this time when I try to build FMU again, one error happened?
can you help me to solve it?
thank you. Hello, all:
I try to create a FMU for Linux in windows system. but after I have met one error when I try to build. see following:
Failed to set up the docker environment for cross-platform compilation because the container could not be retrieved. If the computer does not have internet access, check documentation for manually downloading the docker container.
docker container failed to start
a few weeks ago, I alread successed creat a FMU for Linux in windows system. but I don’t know why this time when I try to build FMU again, one error happened?
can you help me to solve it?
thank you. fmu linux MATLAB Answers — New Questions
Pulse width modulation using simscape blocks
I am trying to model DC motor control by PWM. I tried to model the PWM with in built simscape blocks. When I connect scopes across the H bridge, it is the same as the input constant DC voltage.
I have attached the picture of the model and the plot.
I used part of the exact same model from the example (‘simscapeelectrical/PWMControlledDCMotorExample’)
What is the problem here?I am trying to model DC motor control by PWM. I tried to model the PWM with in built simscape blocks. When I connect scopes across the H bridge, it is the same as the input constant DC voltage.
I have attached the picture of the model and the plot.
I used part of the exact same model from the example (‘simscapeelectrical/PWMControlledDCMotorExample’)
What is the problem here? I am trying to model DC motor control by PWM. I tried to model the PWM with in built simscape blocks. When I connect scopes across the H bridge, it is the same as the input constant DC voltage.
I have attached the picture of the model and the plot.
I used part of the exact same model from the example (‘simscapeelectrical/PWMControlledDCMotorExample’)
What is the problem here? pwm, electric_motor_control MATLAB Answers — New Questions
How to remove black (no perfectly black) background and calculate area of cracks?
Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1)Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1) Dear all,
I’m trying to remove the background (not perfectly black) from the attached image. I have tried many methods, including setting thresholds and visualizing the data with the attached code. However, I realized that this might not be the best approach for this image because it also removes information within the circle (tomography of a cylindrical sample). I believe the best way would be to define a mask with the radius of the circle, but I don’t know how to determine it. Can anyone help fix the issues in my code or define a new one for the circular mask? The final aim is to calculate the area of the cracks.
I really appreciate any help!
clear all
close all
clc
I= imread(‘image_1567.png’);
FG = fliplr(imadjust(I,[0.05 1]));
sout = size(I);
squaresize = [10 10];
xx = mod(0:(sout(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(sout(1)-1),squaresize(1)*2)<squaresize(1);
BG = im2uint8(0.3 + bsxfun(@xor,xx,yy’)*0.4);
mask = FG>10;
outpict = BG;
outpict(mask) = FG(mask);
outpict = uint8(double(FG).*mask + double(BG).*(1-mask));
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(outpict);
[counts, grayLevels] = imhist(outpict);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(outpict(:))]);
title(‘Histogram of output image with threshold 60’);
subplot(3,2,4);
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = outpict > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 60’);
f.InvertHardcopy = ‘off’;
figure (1) image segmentation, imshow, imhist, background, image analysis MATLAB Answers — New Questions
How to programmatically change the command window text size?
It is of course possible to change the command window’s text size by setting preferences, using the GUI. Is there a way to do the same programmatically by executing a MATLAB command or script? That would be much more convenient (I am calling MATLAB through engOpen() from C). At the moment MATLAB is using a 6-pixel font on my hi-dpi monitor (3840×2160), which is really inconvenient. The console has a menu bar, but it offers none of the functionality a normal OS cmd window has.It is of course possible to change the command window’s text size by setting preferences, using the GUI. Is there a way to do the same programmatically by executing a MATLAB command or script? That would be much more convenient (I am calling MATLAB through engOpen() from C). At the moment MATLAB is using a 6-pixel font on my hi-dpi monitor (3840×2160), which is really inconvenient. The console has a menu bar, but it offers none of the functionality a normal OS cmd window has. It is of course possible to change the command window’s text size by setting preferences, using the GUI. Is there a way to do the same programmatically by executing a MATLAB command or script? That would be much more convenient (I am calling MATLAB through engOpen() from C). At the moment MATLAB is using a 6-pixel font on my hi-dpi monitor (3840×2160), which is really inconvenient. The console has a menu bar, but it offers none of the functionality a normal OS cmd window has. command window, change text size, engopen, c interface MATLAB Answers — New Questions
Trying to train PPO RL agent
Hello,
I’m trying to train a PPO agent, but I’m encountering the following issue:
From a certain time, the agent don’t learn anymore (although the agent is only in a local maximum). Let’s say that for the ten first episodes the agent gets a very bad reward, since it’s actually perfoming bad. Then, on the 11th episode (see graph below), the agent found a local maxmimum by updating its actions value to 30 and -30 (these are the gains coefficients of a PI controller). Finally, starting from the 12th episode (i.e. the next one), the agent don’t update its action values anymore.
As a solution, I’ve already tried to increase the EntropyLossWeight, from 0.02 to 1. I’ve tried a lot of values in this range, and it seems like nothing is efficient.
Another parameter may influence the result: from different actions taken in a very wide range of values (e.g. from [1; ∞] for the first action) any system output is perceptible, and thus any variation in the reward can’t be seen watever the action value taken within this range of values. In another words, on the picture below, the agent tried three differents values of gains, but the three actions values produced the same result, So, maybe the agent can’t learn from it.
So, I would like it to continue exploring, although it just got a better reward, since it is still not the best it can achieve.
Link to PPO agent options, including EntropyLossWeight: Options for PPO agent – MATLAB – MathWorks Switzerland
Any help would be very kind!
Thanks a lot in advance!
NicolasHello,
I’m trying to train a PPO agent, but I’m encountering the following issue:
From a certain time, the agent don’t learn anymore (although the agent is only in a local maximum). Let’s say that for the ten first episodes the agent gets a very bad reward, since it’s actually perfoming bad. Then, on the 11th episode (see graph below), the agent found a local maxmimum by updating its actions value to 30 and -30 (these are the gains coefficients of a PI controller). Finally, starting from the 12th episode (i.e. the next one), the agent don’t update its action values anymore.
As a solution, I’ve already tried to increase the EntropyLossWeight, from 0.02 to 1. I’ve tried a lot of values in this range, and it seems like nothing is efficient.
Another parameter may influence the result: from different actions taken in a very wide range of values (e.g. from [1; ∞] for the first action) any system output is perceptible, and thus any variation in the reward can’t be seen watever the action value taken within this range of values. In another words, on the picture below, the agent tried three differents values of gains, but the three actions values produced the same result, So, maybe the agent can’t learn from it.
So, I would like it to continue exploring, although it just got a better reward, since it is still not the best it can achieve.
Link to PPO agent options, including EntropyLossWeight: Options for PPO agent – MATLAB – MathWorks Switzerland
Any help would be very kind!
Thanks a lot in advance!
Nicolas Hello,
I’m trying to train a PPO agent, but I’m encountering the following issue:
From a certain time, the agent don’t learn anymore (although the agent is only in a local maximum). Let’s say that for the ten first episodes the agent gets a very bad reward, since it’s actually perfoming bad. Then, on the 11th episode (see graph below), the agent found a local maxmimum by updating its actions value to 30 and -30 (these are the gains coefficients of a PI controller). Finally, starting from the 12th episode (i.e. the next one), the agent don’t update its action values anymore.
As a solution, I’ve already tried to increase the EntropyLossWeight, from 0.02 to 1. I’ve tried a lot of values in this range, and it seems like nothing is efficient.
Another parameter may influence the result: from different actions taken in a very wide range of values (e.g. from [1; ∞] for the first action) any system output is perceptible, and thus any variation in the reward can’t be seen watever the action value taken within this range of values. In another words, on the picture below, the agent tried three differents values of gains, but the three actions values produced the same result, So, maybe the agent can’t learn from it.
So, I would like it to continue exploring, although it just got a better reward, since it is still not the best it can achieve.
Link to PPO agent options, including EntropyLossWeight: Options for PPO agent – MATLAB – MathWorks Switzerland
Any help would be very kind!
Thanks a lot in advance!
Nicolas reinforcement learning, ppo, entropy loss weight, local maximum MATLAB Answers — New Questions
How do I draw contours on multiple surfaces so that they line up
I have a 3D plot of a 7 2D curves with 6 surfaces drawn so that tthey connect them. Im looking to draw contours on this figure but the only useful comand I can find is
>> contour3([k1;k2], [x1;x2], [z1;z2], 25, ‘color’, ‘k’, ‘linewidth’, 0.1)
where x1 and z1 are the data for my first curve and k1 is used to determine its position in 3D by fixing it. The problem im having is that the command is drawing 25 contours evenly spaced from the maximum value and minimum value out of z1 and z2 causing it to missmatch with 3rd set of contours as z2 has a much greater maximum value compared to z3 and z4. How can i go about creating contours that wont have this problem? The plot with out contours and a plot with contours along with it rotated can be seen below. Hopefully the images illustrates the problem with mismatching contours. Many thanks in advance.I have a 3D plot of a 7 2D curves with 6 surfaces drawn so that tthey connect them. Im looking to draw contours on this figure but the only useful comand I can find is
>> contour3([k1;k2], [x1;x2], [z1;z2], 25, ‘color’, ‘k’, ‘linewidth’, 0.1)
where x1 and z1 are the data for my first curve and k1 is used to determine its position in 3D by fixing it. The problem im having is that the command is drawing 25 contours evenly spaced from the maximum value and minimum value out of z1 and z2 causing it to missmatch with 3rd set of contours as z2 has a much greater maximum value compared to z3 and z4. How can i go about creating contours that wont have this problem? The plot with out contours and a plot with contours along with it rotated can be seen below. Hopefully the images illustrates the problem with mismatching contours. Many thanks in advance. I have a 3D plot of a 7 2D curves with 6 surfaces drawn so that tthey connect them. Im looking to draw contours on this figure but the only useful comand I can find is
>> contour3([k1;k2], [x1;x2], [z1;z2], 25, ‘color’, ‘k’, ‘linewidth’, 0.1)
where x1 and z1 are the data for my first curve and k1 is used to determine its position in 3D by fixing it. The problem im having is that the command is drawing 25 contours evenly spaced from the maximum value and minimum value out of z1 and z2 causing it to missmatch with 3rd set of contours as z2 has a much greater maximum value compared to z3 and z4. How can i go about creating contours that wont have this problem? The plot with out contours and a plot with contours along with it rotated can be seen below. Hopefully the images illustrates the problem with mismatching contours. Many thanks in advance. contour, 3d plots, surface MATLAB Answers — New Questions
How can I write a ‘for’ loop that sums up all elements of a vector?
For instance, I have vector a = 1 2 3 4 5, or simply a=[1:5]. How can I write a ‘for’ loop that sums up all the elements while showing intermediate results? I want the last result to be 15, as in, 1+2+3+4+5. So far I’ve only managed to sum up elements like this: 1+2 = 3, 2+3 = 5 and so on. What I want is a ‘for’ loop that factors in the previous summation and sums it up with the next.
The code I’ve written so far is:
a= [1:5]
for i=1:5
c=sum(a(i)+a(i+1))
disp(c)
endFor instance, I have vector a = 1 2 3 4 5, or simply a=[1:5]. How can I write a ‘for’ loop that sums up all the elements while showing intermediate results? I want the last result to be 15, as in, 1+2+3+4+5. So far I’ve only managed to sum up elements like this: 1+2 = 3, 2+3 = 5 and so on. What I want is a ‘for’ loop that factors in the previous summation and sums it up with the next.
The code I’ve written so far is:
a= [1:5]
for i=1:5
c=sum(a(i)+a(i+1))
disp(c)
end For instance, I have vector a = 1 2 3 4 5, or simply a=[1:5]. How can I write a ‘for’ loop that sums up all the elements while showing intermediate results? I want the last result to be 15, as in, 1+2+3+4+5. So far I’ve only managed to sum up elements like this: 1+2 = 3, 2+3 = 5 and so on. What I want is a ‘for’ loop that factors in the previous summation and sums it up with the next.
The code I’ve written so far is:
a= [1:5]
for i=1:5
c=sum(a(i)+a(i+1))
disp(c)
end for loop MATLAB Answers — New Questions