Tag Archives: matlab
Brace indexing error using fitcensemble
I am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platformI am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platform I am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platform fitcensemble, error, brace indexing MATLAB Answers — New Questions
Fail to start parpool on cluster
Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you!Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you! Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you! parpool, cluster, batch-job MATLAB Answers — New Questions
Why do I receive an error when installing MATLAB 6.5 (R13)?
I get the error
ERROR: Unable to Start the Application – the class files could not be loaded
when installing MATLAB 6.x (R12.x / R13).
This error message appears just after the MATLAB 6.x (R12.x / R13) cd has been inserted in the CD-ROM drive.I get the error
ERROR: Unable to Start the Application – the class files could not be loaded
when installing MATLAB 6.x (R12.x / R13).
This error message appears just after the MATLAB 6.x (R12.x / R13) cd has been inserted in the CD-ROM drive. I get the error
ERROR: Unable to Start the Application – the class files could not be loaded
when installing MATLAB 6.x (R12.x / R13).
This error message appears just after the MATLAB 6.x (R12.x / R13) cd has been inserted in the CD-ROM drive. MATLAB Answers — New Questions
How can I integrate Virtual Arduino/Arduino simulator and simulink?
actually i am unable to get an arduino board for now.
I was doing A college project where i have A virtual Arduino circuit on Wokwi. I need to use matlab Simulink interface (GUI) to control Servo motors connected to arduino. ( Those servo motors are controlling a robotic arm. their kinetic equation and everythin else is ready).
please suggest me a good arduino Emulator where it can be interfaced with Simuink GUI.
or if any other method
maybe how to create virtual arduino circuit in simulink and control it with Simulink GUI??
plz suggest me a solution!actually i am unable to get an arduino board for now.
I was doing A college project where i have A virtual Arduino circuit on Wokwi. I need to use matlab Simulink interface (GUI) to control Servo motors connected to arduino. ( Those servo motors are controlling a robotic arm. their kinetic equation and everythin else is ready).
please suggest me a good arduino Emulator where it can be interfaced with Simuink GUI.
or if any other method
maybe how to create virtual arduino circuit in simulink and control it with Simulink GUI??
plz suggest me a solution! actually i am unable to get an arduino board for now.
I was doing A college project where i have A virtual Arduino circuit on Wokwi. I need to use matlab Simulink interface (GUI) to control Servo motors connected to arduino. ( Those servo motors are controlling a robotic arm. their kinetic equation and everythin else is ready).
please suggest me a good arduino Emulator where it can be interfaced with Simuink GUI.
or if any other method
maybe how to create virtual arduino circuit in simulink and control it with Simulink GUI??
plz suggest me a solution! arduino, simulink, matlab gui MATLAB Answers — New Questions
Leader follower approach formation control problem
Hello everyone, I’m Enrica. For a university project I have a task consisting on modeling on simulink three robots of which one leader and two followers. In the first scenario the robot has to follow a linear trajectory while in the second one the trajectory to follow is circular. In both scenarios the robots must start from different positions. For what concern the initial position of the robots, through the delay present in the loops, I tried to set the initial conditions inside the delay block but there is something that doesn’t work. The robots are described through a space-state block on both x and y axes and they are controlled by two different discrete PID, the internal one controls the velocity (that must be mantained constant) while the external one regulates the position. I tried to model the trajectories using the matlab function block and I tuned the PID with the "tune" button. Plotting the robots on the XY graph they don’t follow each other and I’m not able to identify where is the problem, if it’s related to the structure and connections of the simulink scheme or if it’s related to the space-state block or PID settinggs.
For a better understanding, attached you can find simulink and matlab codes (matlab versione R2023A).
Thank you to those who can help meHello everyone, I’m Enrica. For a university project I have a task consisting on modeling on simulink three robots of which one leader and two followers. In the first scenario the robot has to follow a linear trajectory while in the second one the trajectory to follow is circular. In both scenarios the robots must start from different positions. For what concern the initial position of the robots, through the delay present in the loops, I tried to set the initial conditions inside the delay block but there is something that doesn’t work. The robots are described through a space-state block on both x and y axes and they are controlled by two different discrete PID, the internal one controls the velocity (that must be mantained constant) while the external one regulates the position. I tried to model the trajectories using the matlab function block and I tuned the PID with the "tune" button. Plotting the robots on the XY graph they don’t follow each other and I’m not able to identify where is the problem, if it’s related to the structure and connections of the simulink scheme or if it’s related to the space-state block or PID settinggs.
For a better understanding, attached you can find simulink and matlab codes (matlab versione R2023A).
Thank you to those who can help me Hello everyone, I’m Enrica. For a university project I have a task consisting on modeling on simulink three robots of which one leader and two followers. In the first scenario the robot has to follow a linear trajectory while in the second one the trajectory to follow is circular. In both scenarios the robots must start from different positions. For what concern the initial position of the robots, through the delay present in the loops, I tried to set the initial conditions inside the delay block but there is something that doesn’t work. The robots are described through a space-state block on both x and y axes and they are controlled by two different discrete PID, the internal one controls the velocity (that must be mantained constant) while the external one regulates the position. I tried to model the trajectories using the matlab function block and I tuned the PID with the "tune" button. Plotting the robots on the XY graph they don’t follow each other and I’m not able to identify where is the problem, if it’s related to the structure and connections of the simulink scheme or if it’s related to the space-state block or PID settinggs.
For a better understanding, attached you can find simulink and matlab codes (matlab versione R2023A).
Thank you to those who can help me simulink MATLAB Answers — New Questions
where can i find help for simulink models
Hello,
i have a question about simulink in matlab. I am working on my thesis for my uni for which i created a boat navigation system and i want to simulate that system in simulink to tune my pid. In this system there is a gps receiver, an arduino and the rudder component (which is the actuator, the speed is constant). I also have the code required to operate the system. Are there any premade gps objects/models that i can find without purchasing extra toolboxes for matlab? And if there arent, where should i start as a begginer of simulink? All i find is models that i dont understand what they do or how they work.Hello,
i have a question about simulink in matlab. I am working on my thesis for my uni for which i created a boat navigation system and i want to simulate that system in simulink to tune my pid. In this system there is a gps receiver, an arduino and the rudder component (which is the actuator, the speed is constant). I also have the code required to operate the system. Are there any premade gps objects/models that i can find without purchasing extra toolboxes for matlab? And if there arent, where should i start as a begginer of simulink? All i find is models that i dont understand what they do or how they work. Hello,
i have a question about simulink in matlab. I am working on my thesis for my uni for which i created a boat navigation system and i want to simulate that system in simulink to tune my pid. In this system there is a gps receiver, an arduino and the rudder component (which is the actuator, the speed is constant). I also have the code required to operate the system. Are there any premade gps objects/models that i can find without purchasing extra toolboxes for matlab? And if there arent, where should i start as a begginer of simulink? All i find is models that i dont understand what they do or how they work. gps, simulation MATLAB Answers — New Questions
Relative/ Absolute path in Baseline Text
Is it possible to use relative path instead of absolute when adding baseline criteria?Is it possible to use relative path instead of absolute when adding baseline criteria? Is it possible to use relative path instead of absolute when adding baseline criteria? baseline, relative path MATLAB Answers — New Questions
parpool memory allocation per worker
Hello, I’m learning to submit batch jobs on SLURM. Realistically, I can request at most
#SBATCH -n 32
#SBATCH –mem-per-cpu=4G
In other words, I can request 32 cores and 128G of memory.
Now, I want to run a global optimization function (MultiStart) in parallel. Currently, I set the number of workers in parpool to be 32 (equal to the number of cores), but I constantly run into out of memory.
I’m curious if setting the number of workers in parpool to be, say, 16 can resolve this issue. If I’m not mistaken, if I set the number of workers in parpool to be 32, each worker has at most 4G of memory to use, whereas if I set the number of workers in parpool to be 16, each worker has at most 8G of memory to use.
I’d be grateful if you can correct me, or confirm what I wrote. Obviously, I can just try, but the problem is it takes a long time to get out of the queue, and the optimization itself takes days, so I want to make sure what I try makes sense before submitting.
Next, assuming what I wrote makes sense, what happens if I set the number of workers in parpool to be, say, 20, so 32/20 = 1.6 is not an integer.
Thank you for your guidance.Hello, I’m learning to submit batch jobs on SLURM. Realistically, I can request at most
#SBATCH -n 32
#SBATCH –mem-per-cpu=4G
In other words, I can request 32 cores and 128G of memory.
Now, I want to run a global optimization function (MultiStart) in parallel. Currently, I set the number of workers in parpool to be 32 (equal to the number of cores), but I constantly run into out of memory.
I’m curious if setting the number of workers in parpool to be, say, 16 can resolve this issue. If I’m not mistaken, if I set the number of workers in parpool to be 32, each worker has at most 4G of memory to use, whereas if I set the number of workers in parpool to be 16, each worker has at most 8G of memory to use.
I’d be grateful if you can correct me, or confirm what I wrote. Obviously, I can just try, but the problem is it takes a long time to get out of the queue, and the optimization itself takes days, so I want to make sure what I try makes sense before submitting.
Next, assuming what I wrote makes sense, what happens if I set the number of workers in parpool to be, say, 20, so 32/20 = 1.6 is not an integer.
Thank you for your guidance. Hello, I’m learning to submit batch jobs on SLURM. Realistically, I can request at most
#SBATCH -n 32
#SBATCH –mem-per-cpu=4G
In other words, I can request 32 cores and 128G of memory.
Now, I want to run a global optimization function (MultiStart) in parallel. Currently, I set the number of workers in parpool to be 32 (equal to the number of cores), but I constantly run into out of memory.
I’m curious if setting the number of workers in parpool to be, say, 16 can resolve this issue. If I’m not mistaken, if I set the number of workers in parpool to be 32, each worker has at most 4G of memory to use, whereas if I set the number of workers in parpool to be 16, each worker has at most 8G of memory to use.
I’d be grateful if you can correct me, or confirm what I wrote. Obviously, I can just try, but the problem is it takes a long time to get out of the queue, and the optimization itself takes days, so I want to make sure what I try makes sense before submitting.
Next, assuming what I wrote makes sense, what happens if I set the number of workers in parpool to be, say, 20, so 32/20 = 1.6 is not an integer.
Thank you for your guidance. parpool, numworkers, memory MATLAB Answers — New Questions
In the NewMaze function, get the text of the selected branching mode and use it as the second input to the amaze function.
In the NewMaze function, get the text of the selected branching mode and use it as the second input to the amaze function. In these que, in code view iam writing the correct still it shows "Does the NewMaze callback use the value from the branching mode button group?" What to do now??In the NewMaze function, get the text of the selected branching mode and use it as the second input to the amaze function. In these que, in code view iam writing the correct still it shows "Does the NewMaze callback use the value from the branching mode button group?" What to do now?? In the NewMaze function, get the text of the selected branching mode and use it as the second input to the amaze function. In these que, in code view iam writing the correct still it shows "Does the NewMaze callback use the value from the branching mode button group?" What to do now?? newmaze MATLAB Answers — New Questions
unable to add state in model
how to resolve below error?
Getting error on adding state: missing enumeration for statehow to resolve below error?
Getting error on adding state: missing enumeration for state how to resolve below error?
Getting error on adding state: missing enumeration for state stateflow MATLAB Answers — New Questions
can someone explain this error?
Unrecognized method, property, or field ‘CurrentFileIndex’ for class ‘matlab.io.datastore.CombinedDatastore’.
Error in snake (line 41)
if allImages.CurrentFileIndex <= height(aplostisiImages.Files)Unrecognized method, property, or field ‘CurrentFileIndex’ for class ‘matlab.io.datastore.CombinedDatastore’.
Error in snake (line 41)
if allImages.CurrentFileIndex <= height(aplostisiImages.Files) Unrecognized method, property, or field ‘CurrentFileIndex’ for class ‘matlab.io.datastore.CombinedDatastore’.
Error in snake (line 41)
if allImages.CurrentFileIndex <= height(aplostisiImages.Files) image processing, data acquisition MATLAB Answers — New Questions
Same error values are copied for different input parameters when using MATLAB Experiment Manager
I am trying to run the find gains for PID controller for a powertrain using genetic algorithm. In order to find optimal generations and populations of the genetic algorithm I run almost 1600 experminets in which the following parameters change. So, the input of the model is a WLTP drive cycle (1800s) long. I want to see if I train the Genetic Algorithm on only 30s and find the gains and then using those gains run the whole cycle to calculate the error.
But when I run the experiment I get the same error for all the 3 times with same population and generation combinantion:
However, when i check the simulink model the gains are different for each iteration which means the errors are somehow not updated in the table. I have tried different changes in the code but noting works. Here is the code, if someone could suggest some improvements:
function [mean_abs_error] = Experiment2Function1(params)
tend = params.time;
% Measure the current time before running the simulation
start_simulation_time = tic;
no_var = 2;
lb = [params.lbP params.lbI];
ub = [params.ubP params.ubI];
%GA options
ga_opt = optimoptions(‘ga’,’Display’,’off’,’Generations’,params.generations,’PopulationSize’,params.population,’PlotFcns’,@gaplotbestf);
obj_fn = @(k) optimization_PID(k);
%GA Command
[k, best] = ga((obj_fn),no_var,[],[],[],[],lb,ub,[],ga_opt)
% Measure the simulation time
simulation_time = toc(start_simulation_time);
%%
% Calculate Error
tend = 1800;
sim("Model1.slx")
driveCycleTime = DriveCycle(:,1);
driveCycleSpeed = DriveCycle(:,2);
index1800s = driveCycleTime <= tend;
driveCycle1800s = [driveCycleTime(index1800s), driveCycleSpeed(index1800s)];
% Extract the simulated result for the first 1800 seconds
simulatedTime = tout(tout <= tend);
simulatedSpeed = v_act_lim(tout <= tend);
% Interpolate the simulated result to match the drive cycle time points
simulatedSpeedInterp = interp1(simulatedTime, simulatedSpeed, driveCycle1800s(:, 1), ‘linear’);
% Calculate and plot the error
error = (driveCycle1800s(:, 2) – simulatedSpeedInterp)./ driveCycle1800s(:,2)*100;
abs_error = abs(error);
% Exclude Infinite Values
validIndices = isfinite(abs_error);
validAbsError = abs_error(validIndices);
mean_abs_error = mean(validAbsError)
end
The objective function is as follows:
function cost = optimization_PID(k)
assignin("base", "k", k);
sim("Model1.slx");
itae_values = ITAE.Data;
cost = sum(itae_values);
endI am trying to run the find gains for PID controller for a powertrain using genetic algorithm. In order to find optimal generations and populations of the genetic algorithm I run almost 1600 experminets in which the following parameters change. So, the input of the model is a WLTP drive cycle (1800s) long. I want to see if I train the Genetic Algorithm on only 30s and find the gains and then using those gains run the whole cycle to calculate the error.
But when I run the experiment I get the same error for all the 3 times with same population and generation combinantion:
However, when i check the simulink model the gains are different for each iteration which means the errors are somehow not updated in the table. I have tried different changes in the code but noting works. Here is the code, if someone could suggest some improvements:
function [mean_abs_error] = Experiment2Function1(params)
tend = params.time;
% Measure the current time before running the simulation
start_simulation_time = tic;
no_var = 2;
lb = [params.lbP params.lbI];
ub = [params.ubP params.ubI];
%GA options
ga_opt = optimoptions(‘ga’,’Display’,’off’,’Generations’,params.generations,’PopulationSize’,params.population,’PlotFcns’,@gaplotbestf);
obj_fn = @(k) optimization_PID(k);
%GA Command
[k, best] = ga((obj_fn),no_var,[],[],[],[],lb,ub,[],ga_opt)
% Measure the simulation time
simulation_time = toc(start_simulation_time);
%%
% Calculate Error
tend = 1800;
sim("Model1.slx")
driveCycleTime = DriveCycle(:,1);
driveCycleSpeed = DriveCycle(:,2);
index1800s = driveCycleTime <= tend;
driveCycle1800s = [driveCycleTime(index1800s), driveCycleSpeed(index1800s)];
% Extract the simulated result for the first 1800 seconds
simulatedTime = tout(tout <= tend);
simulatedSpeed = v_act_lim(tout <= tend);
% Interpolate the simulated result to match the drive cycle time points
simulatedSpeedInterp = interp1(simulatedTime, simulatedSpeed, driveCycle1800s(:, 1), ‘linear’);
% Calculate and plot the error
error = (driveCycle1800s(:, 2) – simulatedSpeedInterp)./ driveCycle1800s(:,2)*100;
abs_error = abs(error);
% Exclude Infinite Values
validIndices = isfinite(abs_error);
validAbsError = abs_error(validIndices);
mean_abs_error = mean(validAbsError)
end
The objective function is as follows:
function cost = optimization_PID(k)
assignin("base", "k", k);
sim("Model1.slx");
itae_values = ITAE.Data;
cost = sum(itae_values);
end I am trying to run the find gains for PID controller for a powertrain using genetic algorithm. In order to find optimal generations and populations of the genetic algorithm I run almost 1600 experminets in which the following parameters change. So, the input of the model is a WLTP drive cycle (1800s) long. I want to see if I train the Genetic Algorithm on only 30s and find the gains and then using those gains run the whole cycle to calculate the error.
But when I run the experiment I get the same error for all the 3 times with same population and generation combinantion:
However, when i check the simulink model the gains are different for each iteration which means the errors are somehow not updated in the table. I have tried different changes in the code but noting works. Here is the code, if someone could suggest some improvements:
function [mean_abs_error] = Experiment2Function1(params)
tend = params.time;
% Measure the current time before running the simulation
start_simulation_time = tic;
no_var = 2;
lb = [params.lbP params.lbI];
ub = [params.ubP params.ubI];
%GA options
ga_opt = optimoptions(‘ga’,’Display’,’off’,’Generations’,params.generations,’PopulationSize’,params.population,’PlotFcns’,@gaplotbestf);
obj_fn = @(k) optimization_PID(k);
%GA Command
[k, best] = ga((obj_fn),no_var,[],[],[],[],lb,ub,[],ga_opt)
% Measure the simulation time
simulation_time = toc(start_simulation_time);
%%
% Calculate Error
tend = 1800;
sim("Model1.slx")
driveCycleTime = DriveCycle(:,1);
driveCycleSpeed = DriveCycle(:,2);
index1800s = driveCycleTime <= tend;
driveCycle1800s = [driveCycleTime(index1800s), driveCycleSpeed(index1800s)];
% Extract the simulated result for the first 1800 seconds
simulatedTime = tout(tout <= tend);
simulatedSpeed = v_act_lim(tout <= tend);
% Interpolate the simulated result to match the drive cycle time points
simulatedSpeedInterp = interp1(simulatedTime, simulatedSpeed, driveCycle1800s(:, 1), ‘linear’);
% Calculate and plot the error
error = (driveCycle1800s(:, 2) – simulatedSpeedInterp)./ driveCycle1800s(:,2)*100;
abs_error = abs(error);
% Exclude Infinite Values
validIndices = isfinite(abs_error);
validAbsError = abs_error(validIndices);
mean_abs_error = mean(validAbsError)
end
The objective function is as follows:
function cost = optimization_PID(k)
assignin("base", "k", k);
sim("Model1.slx");
itae_values = ITAE.Data;
cost = sum(itae_values);
end experiment manager, genetic algorithm, error MATLAB Answers — New Questions
s_function 2dof
Hello!!!!
l try to use s_function in simulink and I get this error:
Error in ‘BRAS_2DOF/S-Function1’ while executing MATLAB S-function ‘Dynamique2DOF’, flag = 0 (initialize), at start of simulation.
Caused by:
Subscript indices must either be real positive integers or logicals.
this is my code in joint pieceHello!!!!
l try to use s_function in simulink and I get this error:
Error in ‘BRAS_2DOF/S-Function1’ while executing MATLAB S-function ‘Dynamique2DOF’, flag = 0 (initialize), at start of simulation.
Caused by:
Subscript indices must either be real positive integers or logicals.
this is my code in joint piece Hello!!!!
l try to use s_function in simulink and I get this error:
Error in ‘BRAS_2DOF/S-Function1’ while executing MATLAB S-function ‘Dynamique2DOF’, flag = 0 (initialize), at start of simulation.
Caused by:
Subscript indices must either be real positive integers or logicals.
this is my code in joint piece error sfuntion 2dof MATLAB Answers — New Questions
How do I implement typedefs of unions + structure variables in Simulink?
How can I implement a union + structure variable in Simulink so that when I generate code I will get a variable structure with shared access?
I want to duplicate the behaviour of the C-code below so I can use typedef struct in several similar data sets.
%Code using C
typedef struct st_module_data{
struct st_FaultInfo{
union{
uint8 AllFaults;
struct {
uint8 OVP :1;
uint8 OVW :1;
uint8 UVP :1;
uint8 UVW :1;
uint8 OCP :1;
uint8 OCW :1;
uint8 OTP :1;
uint8 OTW :1;
}
}
}Fault;
struct st_MeasuredData{
uint8 voltage = 0;
uint8 current = 0;
uint8 temperature = 0;
}Measured;
};
st_module_data s_module_01;
s_module_01.Fault.AllFaults = 0; % Clears all flags
s_module_01.Fault.OVP = 1; % Sets only the OVP flag
s_module_01.Measured.voltage = ui8_ADC_5V; % Sets the measured voltage to 5V
I was able to recreate the structure and "typedef"-ish callbacks in matlab by using bus editor:
But I am unable to get the union thing working and can only access the lowest heirarchy of the structure – e.g.:
s_module_01.Fault.AllFaults = 0; % How do I implement this?
s_module_01.Fault = 0; % Does not work…
s_module_01.Fault.OVP = 1; % OK – works in Matlab Functions, Simulink and Stateflow
s_module_01.Measured.voltage = ui8_ADC_5V; % OK – works in Matlab Functions, Simulink and StateflowHow can I implement a union + structure variable in Simulink so that when I generate code I will get a variable structure with shared access?
I want to duplicate the behaviour of the C-code below so I can use typedef struct in several similar data sets.
%Code using C
typedef struct st_module_data{
struct st_FaultInfo{
union{
uint8 AllFaults;
struct {
uint8 OVP :1;
uint8 OVW :1;
uint8 UVP :1;
uint8 UVW :1;
uint8 OCP :1;
uint8 OCW :1;
uint8 OTP :1;
uint8 OTW :1;
}
}
}Fault;
struct st_MeasuredData{
uint8 voltage = 0;
uint8 current = 0;
uint8 temperature = 0;
}Measured;
};
st_module_data s_module_01;
s_module_01.Fault.AllFaults = 0; % Clears all flags
s_module_01.Fault.OVP = 1; % Sets only the OVP flag
s_module_01.Measured.voltage = ui8_ADC_5V; % Sets the measured voltage to 5V
I was able to recreate the structure and "typedef"-ish callbacks in matlab by using bus editor:
But I am unable to get the union thing working and can only access the lowest heirarchy of the structure – e.g.:
s_module_01.Fault.AllFaults = 0; % How do I implement this?
s_module_01.Fault = 0; % Does not work…
s_module_01.Fault.OVP = 1; % OK – works in Matlab Functions, Simulink and Stateflow
s_module_01.Measured.voltage = ui8_ADC_5V; % OK – works in Matlab Functions, Simulink and Stateflow How can I implement a union + structure variable in Simulink so that when I generate code I will get a variable structure with shared access?
I want to duplicate the behaviour of the C-code below so I can use typedef struct in several similar data sets.
%Code using C
typedef struct st_module_data{
struct st_FaultInfo{
union{
uint8 AllFaults;
struct {
uint8 OVP :1;
uint8 OVW :1;
uint8 UVP :1;
uint8 UVW :1;
uint8 OCP :1;
uint8 OCW :1;
uint8 OTP :1;
uint8 OTW :1;
}
}
}Fault;
struct st_MeasuredData{
uint8 voltage = 0;
uint8 current = 0;
uint8 temperature = 0;
}Measured;
};
st_module_data s_module_01;
s_module_01.Fault.AllFaults = 0; % Clears all flags
s_module_01.Fault.OVP = 1; % Sets only the OVP flag
s_module_01.Measured.voltage = ui8_ADC_5V; % Sets the measured voltage to 5V
I was able to recreate the structure and "typedef"-ish callbacks in matlab by using bus editor:
But I am unable to get the union thing working and can only access the lowest heirarchy of the structure – e.g.:
s_module_01.Fault.AllFaults = 0; % How do I implement this?
s_module_01.Fault = 0; % Does not work…
s_module_01.Fault.OVP = 1; % OK – works in Matlab Functions, Simulink and Stateflow
s_module_01.Measured.voltage = ui8_ADC_5V; % OK – works in Matlab Functions, Simulink and Stateflow simulink, stateflow, simulink bus editor, structures, union MATLAB Answers — New Questions
Can I export all the trained model from the classification learner app, using a single command?
Dear experts,
I am trying to find out which model performs on a specific dataset. There are 34 models available in the classification learner app. Do we have any option to export all the 34 trained model using a single command? Presently, I’m doing it one at a time.
Thank you in advance.Dear experts,
I am trying to find out which model performs on a specific dataset. There are 34 models available in the classification learner app. Do we have any option to export all the 34 trained model using a single command? Presently, I’m doing it one at a time.
Thank you in advance. Dear experts,
I am trying to find out which model performs on a specific dataset. There are 34 models available in the classification learner app. Do we have any option to export all the 34 trained model using a single command? Presently, I’m doing it one at a time.
Thank you in advance. matlab classification learner app MATLAB Answers — New Questions
Decrease Existing UIGridLayout RowHeight (or ColumnWidth)
I’m trying to decrease an existing uigridlayout’s number of rows and columns. Below I created the figure and grid.
fig = uifigure; % make uifigure
g = uigridlayout(fig); % put uigridlayout in fig
g.RowHeight = {‘1x’ ‘1x’ ‘1x’ ‘1x’}; % assign to uigridlayout 4 rows
g.ColumnWidth = {‘1x’ ‘1x’}; % assign to uigridlayout 2 columns
So, it already exists and has a specified row height and column width dimensions. And I want to change the number of rows and columns in this existing uigridlayout (g)… instead of deleting it and making a new one with the desired number of rows and columnns (e.g. a grid with 3 rows and 3 columns).
I am able to add rows or columns –>
g.ColumnWidth = {‘1x’ ‘1x’ ‘1x’} % assign greater amount of columns to g.ColumnWidth property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
But I can’t seem to be able to remove rows or columns –>
g.RowHeight = {‘1x’ ‘1x’ ‘1x’} % assign lower amount of columns to g.RowHeight property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
How do I decrease the number of rows or columns in this existing uigridlayout?I’m trying to decrease an existing uigridlayout’s number of rows and columns. Below I created the figure and grid.
fig = uifigure; % make uifigure
g = uigridlayout(fig); % put uigridlayout in fig
g.RowHeight = {‘1x’ ‘1x’ ‘1x’ ‘1x’}; % assign to uigridlayout 4 rows
g.ColumnWidth = {‘1x’ ‘1x’}; % assign to uigridlayout 2 columns
So, it already exists and has a specified row height and column width dimensions. And I want to change the number of rows and columns in this existing uigridlayout (g)… instead of deleting it and making a new one with the desired number of rows and columnns (e.g. a grid with 3 rows and 3 columns).
I am able to add rows or columns –>
g.ColumnWidth = {‘1x’ ‘1x’ ‘1x’} % assign greater amount of columns to g.ColumnWidth property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
But I can’t seem to be able to remove rows or columns –>
g.RowHeight = {‘1x’ ‘1x’ ‘1x’} % assign lower amount of columns to g.RowHeight property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
How do I decrease the number of rows or columns in this existing uigridlayout? I’m trying to decrease an existing uigridlayout’s number of rows and columns. Below I created the figure and grid.
fig = uifigure; % make uifigure
g = uigridlayout(fig); % put uigridlayout in fig
g.RowHeight = {‘1x’ ‘1x’ ‘1x’ ‘1x’}; % assign to uigridlayout 4 rows
g.ColumnWidth = {‘1x’ ‘1x’}; % assign to uigridlayout 2 columns
So, it already exists and has a specified row height and column width dimensions. And I want to change the number of rows and columns in this existing uigridlayout (g)… instead of deleting it and making a new one with the desired number of rows and columnns (e.g. a grid with 3 rows and 3 columns).
I am able to add rows or columns –>
g.ColumnWidth = {‘1x’ ‘1x’ ‘1x’} % assign greater amount of columns to g.ColumnWidth property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
But I can’t seem to be able to remove rows or columns –>
g.RowHeight = {‘1x’ ‘1x’ ‘1x’} % assign lower amount of columns to g.RowHeight property
output –>
g =
GridLayout with properties:
RowHeight: {‘1x’ ‘1x’ ‘1x’ ‘1x’}
ColumnWidth: {‘1x’ ‘1x’ ‘1x’}
How do I decrease the number of rows or columns in this existing uigridlayout? uifigure, uigridlayout, rows and columns, editing properties MATLAB Answers — New Questions
How to continue drawing bar charts on the basis of drawing maps
How to continue drawing bar charts on the basis of drawing maps using MATLAB softwore? Just like this one.How to continue drawing bar charts on the basis of drawing maps using MATLAB softwore? Just like this one. How to continue drawing bar charts on the basis of drawing maps using MATLAB softwore? Just like this one. mapping toolbox MATLAB Answers — New Questions
try catch does not catch an error in save function
Consider
try
statements
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
where statements is a block of codes. I’m sure that statements is a good block of codes, i.e., without errors. This leads to no display of message, and it fails to save (because the directory does not exist).
On the other hand,
statements
try
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
Now, this does lead to displaying
Cannot create ‘kimscalprr.mat’ because ‘gpfshomejk23bdkimjmp_25may2024MATLAB’ does not exist.
as it should. I’m finding that save has a lot of issues besides this, but this seems the most basic. Can anyone tell me why this difference occurs?
Thank youConsider
try
statements
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
where statements is a block of codes. I’m sure that statements is a good block of codes, i.e., without errors. This leads to no display of message, and it fails to save (because the directory does not exist).
On the other hand,
statements
try
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
Now, this does lead to displaying
Cannot create ‘kimscalprr.mat’ because ‘gpfshomejk23bdkimjmp_25may2024MATLAB’ does not exist.
as it should. I’m finding that save has a lot of issues besides this, but this seems the most basic. Can anyone tell me why this difference occurs?
Thank you Consider
try
statements
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
where statements is a block of codes. I’m sure that statements is a good block of codes, i.e., without errors. This leads to no display of message, and it fails to save (because the directory does not exist).
On the other hand,
statements
try
save("/gpfs/home/jk23bd/kimjmp_25may2024/MATLAB/kimscalprr.mat","kimScalingPriors");
catch ME
disp(ME.message)
end
Now, this does lead to displaying
Cannot create ‘kimscalprr.mat’ because ‘gpfshomejk23bdkimjmp_25may2024MATLAB’ does not exist.
as it should. I’m finding that save has a lot of issues besides this, but this seems the most basic. Can anyone tell me why this difference occurs?
Thank you try, catch, error, save MATLAB Answers — New Questions
我不知道应该输入的密钥是什么?
已经安装好,但是启动需要密钥。我不知道应该输入什么?已经安装好,但是启动需要密钥。我不知道应该输入什么? 已经安装好,但是启动需要密钥。我不知道应该输入什么? secrete key MATLAB Answers — New Questions
Matlab Engine API for Python: multidimarray for python
I am trying to install matlab engine api for python and i am using google colab for python. I installed matlab engine api for python using the steps mentioned in the documentation for MacOS but multidimarrayforpython is not getting downloaded.I am trying to install matlab engine api for python and i am using google colab for python. I installed matlab engine api for python using the steps mentioned in the documentation for MacOS but multidimarrayforpython is not getting downloaded. I am trying to install matlab engine api for python and i am using google colab for python. I installed matlab engine api for python using the steps mentioned in the documentation for MacOS but multidimarrayforpython is not getting downloaded. matlab engine api for python, multidimarrayforpython MATLAB Answers — New Questions