Category: Matlab
Category Archives: Matlab
Axis exponent causing all text in the figure to render as curves instead of text in svg
I’m using the saveas function to export a figure as an svg file. I have set the renderer to be painters but occasionally the output of text is rendered as curves in the svg file.
Everything works fine except when using greek letters in axis labels (which I have avoided) or when the axis label contains exponents automatically by MATLAB. If I delete the " x 10^5 " part manually in the figure window or in the code I include ax = gca; ax.YAxis.Exponent = 0, then the saveas works fine exporting an svg file with text rendered as text. However, this is still a hassle and I’m hoping it can be fixed.
I’m using R2024a.I’m using the saveas function to export a figure as an svg file. I have set the renderer to be painters but occasionally the output of text is rendered as curves in the svg file.
Everything works fine except when using greek letters in axis labels (which I have avoided) or when the axis label contains exponents automatically by MATLAB. If I delete the " x 10^5 " part manually in the figure window or in the code I include ax = gca; ax.YAxis.Exponent = 0, then the saveas works fine exporting an svg file with text rendered as text. However, this is still a hassle and I’m hoping it can be fixed.
I’m using R2024a. I’m using the saveas function to export a figure as an svg file. I have set the renderer to be painters but occasionally the output of text is rendered as curves in the svg file.
Everything works fine except when using greek letters in axis labels (which I have avoided) or when the axis label contains exponents automatically by MATLAB. If I delete the " x 10^5 " part manually in the figure window or in the code I include ax = gca; ax.YAxis.Exponent = 0, then the saveas works fine exporting an svg file with text rendered as text. However, this is still a hassle and I’m hoping it can be fixed.
I’m using R2024a. svg, vector graphics, curves, axis labels MATLAB Answers — New Questions
​
Why does the MathWorks Service Host create several files on my machine?
Why does the MathWorks Service Host create several files on my machine?Why does the MathWorks Service Host create several files on my machine? Why does the MathWorks Service Host create several files on my machine?  MATLAB Answers — New Questions
​
Why does MATLAB R2021b or newer create a large directory of data for each user in ~/.MathWorks, %localappdata%MathWorks, or ~/Library/Application Support/MathWorks?
Why does MATLAB R2021b or newer create a large directory of data for each user in ~/.MathWorks, %localappdata%MathWorks, or ~/Library/Application Support/MathWorks?Why does MATLAB R2021b or newer create a large directory of data for each user in ~/.MathWorks, %localappdata%MathWorks, or ~/Library/Application Support/MathWorks? Why does MATLAB R2021b or newer create a large directory of data for each user in ~/.MathWorks, %localappdata%MathWorks, or ~/Library/Application Support/MathWorks?  MATLAB Answers — New Questions
​
Simulink communication with a second, real time process on the same Windows PC
For a non-Simulink real time process running on a Windows PC is UDP the best way to communicate with Simulink running on the same PC? Is Simulink Desktop Real-Time the best product for this?For a non-Simulink real time process running on a Windows PC is UDP the best way to communicate with Simulink running on the same PC? Is Simulink Desktop Real-Time the best product for this? For a non-Simulink real time process running on a Windows PC is UDP the best way to communicate with Simulink running on the same PC? Is Simulink Desktop Real-Time the best product for this? udp, simulink, windows pc, separate process MATLAB Answers — New Questions
​
Why is the MathWorks Service Host causing issues with my cluster and/or HPC?
Why is the MathWorks Service Host causing issues with my cluster and/or HPC?Why is the MathWorks Service Host causing issues with my cluster and/or HPC? Why is the MathWorks Service Host causing issues with my cluster and/or HPC?  MATLAB Answers — New Questions
​
Deep learning using trainnet for resnet18 : old trainnetwork –> new trainnet
Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help!Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help! Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help! deep learning, semantic segmentation, resnet18, trainnet MATLAB Answers — New Questions
​
Issues setting CoordinateSystem for sim3d.Actor to MATLAB in Simulink; need correct initialization method. Also need third-person view in Simulation 3D Scene Configuration
I’m encountering issues when trying to set the CoordinateSystem property for the sim3d.Actor object in Simulink. According to the documentation, this property should be configurable to use the MATLAB coordinate system, but it results in an error. I need guidance on the correct method to achieve this in the initialization script.
Additionally, I want to configure the Simulation 3D Scene Configuration block so that when selecting my Actor defined in the Simulation 3D Actor block as the Scene view, the view is in third person rather than the default coordinates [0 0 0].
Issue 1: Changing Coordinate System
I am trying to set the CoordinateSystem property for a sim3d.Actor object to use the MATLAB coordinate system. Here is the current initialization script:
fileName = "QuadCopter_Body.stl";
Body = sim3d.Actor(‘ActorName’, ‘Body’, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle, …
‘CoordinateSystem’, ‘MATLAB’);
World.add(Body, Actor);
Body.load(fileName, [1 1 1]/100);
Body.Color = [0, 0, 1];
Body.Scale = [10 10 10];
Translation = [0.341 0.286 0.042;
-0.341 0.286 0.042;
0.341 -0.286 0.042;
-0.341 -0.286 0.042];
propellerFileName = "QuadCopter_Propeller.stl";
for propellerIndex = 1:4
actorName = sprintf(‘Propeller%d’, propellerIndex);
Propeller = sim3d.Actor(‘ActorName’,actorName, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle);
World.add(Propeller, Actor);
Propeller.load(propellerFileName, [1 1 1]/100);
Propeller.Color = [1, 0, 0];
Propeller.Translation = Translation(propellerIndex, :);
Propeller.Rotation = [0 0 0 ];
Propeller.Scale = [10 10 10];
end
Actor.save("quadcopter.mat")
This is the error:
‘CoordinateSystem’ is not a recognized parameter. For a list of valid name-value pair argument, see the documentation for this function.
Issue 2: Setting Third-Person View
I also want to set the view in the Simulation 3D Scene Configuration block to be in third person when selecting my Actor defined in the Simulation 3D Actor block. Currently, the view defaults to the coordinates [0 0 0]. How can I change this view to a third-person perspective?I’m encountering issues when trying to set the CoordinateSystem property for the sim3d.Actor object in Simulink. According to the documentation, this property should be configurable to use the MATLAB coordinate system, but it results in an error. I need guidance on the correct method to achieve this in the initialization script.
Additionally, I want to configure the Simulation 3D Scene Configuration block so that when selecting my Actor defined in the Simulation 3D Actor block as the Scene view, the view is in third person rather than the default coordinates [0 0 0].
Issue 1: Changing Coordinate System
I am trying to set the CoordinateSystem property for a sim3d.Actor object to use the MATLAB coordinate system. Here is the current initialization script:
fileName = "QuadCopter_Body.stl";
Body = sim3d.Actor(‘ActorName’, ‘Body’, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle, …
‘CoordinateSystem’, ‘MATLAB’);
World.add(Body, Actor);
Body.load(fileName, [1 1 1]/100);
Body.Color = [0, 0, 1];
Body.Scale = [10 10 10];
Translation = [0.341 0.286 0.042;
-0.341 0.286 0.042;
0.341 -0.286 0.042;
-0.341 -0.286 0.042];
propellerFileName = "QuadCopter_Propeller.stl";
for propellerIndex = 1:4
actorName = sprintf(‘Propeller%d’, propellerIndex);
Propeller = sim3d.Actor(‘ActorName’,actorName, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle);
World.add(Propeller, Actor);
Propeller.load(propellerFileName, [1 1 1]/100);
Propeller.Color = [1, 0, 0];
Propeller.Translation = Translation(propellerIndex, :);
Propeller.Rotation = [0 0 0 ];
Propeller.Scale = [10 10 10];
end
Actor.save("quadcopter.mat")
This is the error:
‘CoordinateSystem’ is not a recognized parameter. For a list of valid name-value pair argument, see the documentation for this function.
Issue 2: Setting Third-Person View
I also want to set the view in the Simulation 3D Scene Configuration block to be in third person when selecting my Actor defined in the Simulation 3D Actor block. Currently, the view defaults to the coordinates [0 0 0]. How can I change this view to a third-person perspective? I’m encountering issues when trying to set the CoordinateSystem property for the sim3d.Actor object in Simulink. According to the documentation, this property should be configurable to use the MATLAB coordinate system, but it results in an error. I need guidance on the correct method to achieve this in the initialization script.
Additionally, I want to configure the Simulation 3D Scene Configuration block so that when selecting my Actor defined in the Simulation 3D Actor block as the Scene view, the view is in third person rather than the default coordinates [0 0 0].
Issue 1: Changing Coordinate System
I am trying to set the CoordinateSystem property for a sim3d.Actor object to use the MATLAB coordinate system. Here is the current initialization script:
fileName = "QuadCopter_Body.stl";
Body = sim3d.Actor(‘ActorName’, ‘Body’, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle, …
‘CoordinateSystem’, ‘MATLAB’);
World.add(Body, Actor);
Body.load(fileName, [1 1 1]/100);
Body.Color = [0, 0, 1];
Body.Scale = [10 10 10];
Translation = [0.341 0.286 0.042;
-0.341 0.286 0.042;
0.341 -0.286 0.042;
-0.341 -0.286 0.042];
propellerFileName = "QuadCopter_Propeller.stl";
for propellerIndex = 1:4
actorName = sprintf(‘Propeller%d’, propellerIndex);
Propeller = sim3d.Actor(‘ActorName’,actorName, …
‘Mobility’, sim3d.utils.MobilityTypes.Movable, …
‘ActorClassId’, sim3d.utils.SemanticType.Vehicle);
World.add(Propeller, Actor);
Propeller.load(propellerFileName, [1 1 1]/100);
Propeller.Color = [1, 0, 0];
Propeller.Translation = Translation(propellerIndex, :);
Propeller.Rotation = [0 0 0 ];
Propeller.Scale = [10 10 10];
end
Actor.save("quadcopter.mat")
This is the error:
‘CoordinateSystem’ is not a recognized parameter. For a list of valid name-value pair argument, see the documentation for this function.
Issue 2: Setting Third-Person View
I also want to set the view in the Simulation 3D Scene Configuration block to be in third person when selecting my Actor defined in the Simulation 3D Actor block. Currently, the view defaults to the coordinates [0 0 0]. How can I change this view to a third-person perspective? sim3d, coordinatesystem, simulation3dactor, sceneconfiguration, simulink MATLAB Answers — New Questions
​
Python Module not found when call the python function using Matlab
I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels);I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels);Â I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels); matlab, python MATLAB Answers — New Questions
​
Error in ode45 “inputs must be floats, namely single or double” when solving rocket flight equation.
Im trying to solve a non-linear first order differential equation with ode45, with a weird function thrust_cont thats supposed to describe the thrust of a model rocket.
syms v(t) a(t) y(t) thrust_complete(t) t diff_equation(t,v) thrust_cont(t) thrust_cont(t)
thrust_clean = [0,0.176;0.001,0.198;0.002,0.381;0.003,0.414;0.004,0.176;0.005,0.104;0.006,0.27;0.007,0.17;0.008,0.201;0.009,0.107;0.01,0.248;0.011,0.159;0.012,0.1……..rest of the data; this is [time in ms, Force]
thrust_clean (1634:20000,:) = 0;
for n=1634:1:20000
thrust_clean (n:20000,1) = n/1000;
end
grad = 100;
cf = polyfit(thrust_clean(1:1700,1), thrust_clean(1:1700,2),grad);
thrust_complete = 0;
for g = 1:grad
thrust_complete = thrust_complete + cf(g)*t^(grad+1-g);
end
thrust_cont = heaviside(t) * thrust_complete * heaviside(1.633-t);
fplot(thrust_cont, [0,2])
m = 0.14;
C_probar = 2.3;
rho = 1.29;
A = pi*0.05*0.05;
C_d = 0.75;
span = [0,20];
diff_equation = thrust_cont/m – 9.8 -((C_d*rho*A*C_probar/(m*2))*(v(t)^2));
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
in the bold highlighted line i have my final version of the continous thrust curve function, which i had to manipulate quite a bit (cause im not very good at matlab unfortunately). Then i define a couple of normal variables, and then the problem, i define my equation (which the right hand side is equal to the derivative of v), and I try to use the ode45 function, only for it to return the following error message:
Error using superiorfloat
Inputs must be floats, namely single or double.
Error in odearguments (line 114)
dataType = superiorfloat(t0,y0,f0);
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in TBD_matlab (line 23)
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
I don’t even understand what the error is referring to or even trying to tell me, and I’ve been trying for quite some time now to move things around but nothing seems to work. I previously actually had tried to use dsolve to get an answer, but it found no analytical solution. If anybody has the slightest idea what could be happening i’d be grateful đź‘ŤIm trying to solve a non-linear first order differential equation with ode45, with a weird function thrust_cont thats supposed to describe the thrust of a model rocket.
syms v(t) a(t) y(t) thrust_complete(t) t diff_equation(t,v) thrust_cont(t) thrust_cont(t)
thrust_clean = [0,0.176;0.001,0.198;0.002,0.381;0.003,0.414;0.004,0.176;0.005,0.104;0.006,0.27;0.007,0.17;0.008,0.201;0.009,0.107;0.01,0.248;0.011,0.159;0.012,0.1……..rest of the data; this is [time in ms, Force]
thrust_clean (1634:20000,:) = 0;
for n=1634:1:20000
thrust_clean (n:20000,1) = n/1000;
end
grad = 100;
cf = polyfit(thrust_clean(1:1700,1), thrust_clean(1:1700,2),grad);
thrust_complete = 0;
for g = 1:grad
thrust_complete = thrust_complete + cf(g)*t^(grad+1-g);
end
thrust_cont = heaviside(t) * thrust_complete * heaviside(1.633-t);
fplot(thrust_cont, [0,2])
m = 0.14;
C_probar = 2.3;
rho = 1.29;
A = pi*0.05*0.05;
C_d = 0.75;
span = [0,20];
diff_equation = thrust_cont/m – 9.8 -((C_d*rho*A*C_probar/(m*2))*(v(t)^2));
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
in the bold highlighted line i have my final version of the continous thrust curve function, which i had to manipulate quite a bit (cause im not very good at matlab unfortunately). Then i define a couple of normal variables, and then the problem, i define my equation (which the right hand side is equal to the derivative of v), and I try to use the ode45 function, only for it to return the following error message:
Error using superiorfloat
Inputs must be floats, namely single or double.
Error in odearguments (line 114)
dataType = superiorfloat(t0,y0,f0);
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in TBD_matlab (line 23)
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
I don’t even understand what the error is referring to or even trying to tell me, and I’ve been trying for quite some time now to move things around but nothing seems to work. I previously actually had tried to use dsolve to get an answer, but it found no analytical solution. If anybody has the slightest idea what could be happening i’d be grateful đź‘ŤÂ Im trying to solve a non-linear first order differential equation with ode45, with a weird function thrust_cont thats supposed to describe the thrust of a model rocket.
syms v(t) a(t) y(t) thrust_complete(t) t diff_equation(t,v) thrust_cont(t) thrust_cont(t)
thrust_clean = [0,0.176;0.001,0.198;0.002,0.381;0.003,0.414;0.004,0.176;0.005,0.104;0.006,0.27;0.007,0.17;0.008,0.201;0.009,0.107;0.01,0.248;0.011,0.159;0.012,0.1……..rest of the data; this is [time in ms, Force]
thrust_clean (1634:20000,:) = 0;
for n=1634:1:20000
thrust_clean (n:20000,1) = n/1000;
end
grad = 100;
cf = polyfit(thrust_clean(1:1700,1), thrust_clean(1:1700,2),grad);
thrust_complete = 0;
for g = 1:grad
thrust_complete = thrust_complete + cf(g)*t^(grad+1-g);
end
thrust_cont = heaviside(t) * thrust_complete * heaviside(1.633-t);
fplot(thrust_cont, [0,2])
m = 0.14;
C_probar = 2.3;
rho = 1.29;
A = pi*0.05*0.05;
C_d = 0.75;
span = [0,20];
diff_equation = thrust_cont/m – 9.8 -((C_d*rho*A*C_probar/(m*2))*(v(t)^2));
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
in the bold highlighted line i have my final version of the continous thrust curve function, which i had to manipulate quite a bit (cause im not very good at matlab unfortunately). Then i define a couple of normal variables, and then the problem, i define my equation (which the right hand side is equal to the derivative of v), and I try to use the ode45 function, only for it to return the following error message:
Error using superiorfloat
Inputs must be floats, namely single or double.
Error in odearguments (line 114)
dataType = superiorfloat(t0,y0,f0);
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in TBD_matlab (line 23)
[t, flight] = ode45(@(t,v) diff_equation, span, 0)
I don’t even understand what the error is referring to or even trying to tell me, and I’ve been trying for quite some time now to move things around but nothing seems to work. I previously actually had tried to use dsolve to get an answer, but it found no analytical solution. If anybody has the slightest idea what could be happening i’d be grateful đź‘ŤÂ ode45, matlab, differential equations MATLAB Answers — New Questions
​
How to interpolate values given a starting and end point
I have a voltmeter that I was using to measure voltage on a battery, unfortunatly it wasnt working properly and Im not able to do the test again. Before and after I ran the test I tested the voltage, so I know the real starting (50.6V) and ending (50.3V). My voltmeter recorded the power draw correctly but the values are off, they hover around 18V, how do I interpolate the bad values with a known starting and end point?
Example:
I know its 50.6 to 50.3 and my recordings are 18.2 to 17.9
I want the readings to be 50.6, 50.5, 50.4, 50.3 instead of 18.2, 18.1, 18.0, 17.9. I cant just add the difference because power draw wasnt exactly linear so Im trying to use the interp1 function but it isnt working for me. Thanks!I have a voltmeter that I was using to measure voltage on a battery, unfortunatly it wasnt working properly and Im not able to do the test again. Before and after I ran the test I tested the voltage, so I know the real starting (50.6V) and ending (50.3V). My voltmeter recorded the power draw correctly but the values are off, they hover around 18V, how do I interpolate the bad values with a known starting and end point?
Example:
I know its 50.6 to 50.3 and my recordings are 18.2 to 17.9
I want the readings to be 50.6, 50.5, 50.4, 50.3 instead of 18.2, 18.1, 18.0, 17.9. I cant just add the difference because power draw wasnt exactly linear so Im trying to use the interp1 function but it isnt working for me. Thanks! I have a voltmeter that I was using to measure voltage on a battery, unfortunatly it wasnt working properly and Im not able to do the test again. Before and after I ran the test I tested the voltage, so I know the real starting (50.6V) and ending (50.3V). My voltmeter recorded the power draw correctly but the values are off, they hover around 18V, how do I interpolate the bad values with a known starting and end point?
Example:
I know its 50.6 to 50.3 and my recordings are 18.2 to 17.9
I want the readings to be 50.6, 50.5, 50.4, 50.3 instead of 18.2, 18.1, 18.0, 17.9. I cant just add the difference because power draw wasnt exactly linear so Im trying to use the interp1 function but it isnt working for me. Thanks! volts MATLAB Answers — New Questions
​
Why do I receive License Manager Error -18?
I am getting the following error message:
ERROR: License checkout failed. License server does not support this FEATURE. License Manager Error -18I am getting the following error message:
ERROR: License checkout failed. License server does not support this FEATURE. License Manager Error -18Â I am getting the following error message:
ERROR: License checkout failed. License server does not support this FEATURE. License Manager Error -18  MATLAB Answers — New Questions
​
How can I backup a Polyspace Metrics Server before uninstalling it?
I’m temporarily uninstalling my Polyspace Metrics Server, and I’d like to backup the correct files in the event that I use Polyspace Metrics in the future. What exactly do I need in order to restart this server?I’m temporarily uninstalling my Polyspace Metrics Server, and I’d like to backup the correct files in the event that I use Polyspace Metrics in the future. What exactly do I need in order to restart this server? I’m temporarily uninstalling my Polyspace Metrics Server, and I’d like to backup the correct files in the event that I use Polyspace Metrics in the future. What exactly do I need in order to restart this server? polyspace, metrics, backup, server, file MATLAB Answers — New Questions
​
Flow rate discrepancy between upstream and downstream of orifice model.
I am verifying the flow rate before and after orifice model measured by "Flow Rate Sensor".
The target value of flow rate is 13.2 gpm with diffential pressure 2950 psid and orifice model of orifice area is set to get this flow rate.
Simulation Retuls of flow rate
Before orifice: 13.08 gpm
After orifice: 13.26 gpm
Is there any solution or what is the root cause of this discrepancy?I am verifying the flow rate before and after orifice model measured by "Flow Rate Sensor".
The target value of flow rate is 13.2 gpm with diffential pressure 2950 psid and orifice model of orifice area is set to get this flow rate.
Simulation Retuls of flow rate
Before orifice: 13.08 gpm
After orifice: 13.26 gpm
Is there any solution or what is the root cause of this discrepancy? I am verifying the flow rate before and after orifice model measured by "Flow Rate Sensor".
The target value of flow rate is 13.2 gpm with diffential pressure 2950 psid and orifice model of orifice area is set to get this flow rate.
Simulation Retuls of flow rate
Before orifice: 13.08 gpm
After orifice: 13.26 gpm
Is there any solution or what is the root cause of this discrepancy? flow rate MATLAB Answers — New Questions
​
LSTM TO STRING CATEGORICAL LABELS
Hi Please help with with this code, there are two questions,
Looks like my LSTM cannot achieve any better accuracy – what could be the cause?
At the very end of the code, I wanted to to plot a confusion chart, – 1 – I used a for loop to capture the predicted labels from the trained network, is there a one line command for this type of data structure?
Still on the confusion chart, what would be the best way to create the true labels set, I see the one I used in the function call for confusion chart is really incomplete, I am expecting the true labels set to be 40 x 5 matrix just like the test set.Hi Please help with with this code, there are two questions,
Looks like my LSTM cannot achieve any better accuracy – what could be the cause?
At the very end of the code, I wanted to to plot a confusion chart, – 1 – I used a for loop to capture the predicted labels from the trained network, is there a one line command for this type of data structure?
Still on the confusion chart, what would be the best way to create the true labels set, I see the one I used in the function call for confusion chart is really incomplete, I am expecting the true labels set to be 40 x 5 matrix just like the test set. Hi Please help with with this code, there are two questions,
Looks like my LSTM cannot achieve any better accuracy – what could be the cause?
At the very end of the code, I wanted to to plot a confusion chart, – 1 – I used a for loop to capture the predicted labels from the trained network, is there a one line command for this type of data structure?
Still on the confusion chart, what would be the best way to create the true labels set, I see the one I used in the function call for confusion chart is really incomplete, I am expecting the true labels set to be 40 x 5 matrix just like the test set. lstm MATLAB Answers — New Questions
​
Why do I receive a “Permission denied” error when trying to install with the MATLAB Package Manager?
When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
/tmp/path/to/mpm: Permission denied
How can I resolve this error?When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
/tmp/path/to/mpm: Permission denied
How can I resolve this error? When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
/tmp/path/to/mpm: Permission denied
How can I resolve this error?  MATLAB Answers — New Questions
​
Training 4 TD3 RL Agents in Simulink to control Buck Converter . They need new observations, initialized from Buck Converter outputs. How to learn continuously from 1s to 5s?
I am trying to train 4 TD3 RL Agents in the Simulink Environment. Each Agent is supposed to control the output voltage of a Buck Converter by sending its action signal to the input of the Buck Converter (as a reference voltage). For the sake of improving the learning process and enhancing the exploration of the agents, I want to initiate the environment such that at the beginning of each training episode, the agents observe a new set of observations. The issue is that all 9 elements of the observation vectors depend on the output voltages of the Buck Converters (the Actions). So I need to initialize the model at the beginning of each training episode by initializing the inputs of the Buck Converters, then as the agent starts sampling from the environment, replace the initilizing parameters with the actions of the agents. To implement that, I have put the RL Agent blocks in the Triggered Subsystems, and connected their outputs to Swich Blocks for alternating between the initializing parameter and the output of Triggered Subsystems (Action Signals). from the beginning of the episode till the second 1 of the simulation, the model gets initialize with the initializing parameter, then in the second 1, switch will work, and triggered subsystem will be activated. My question is: How can I modify my code so that the agents start the learning process from seconde 1 till the end of simulation time at seconde 5 (4 seconds of training for each episode)?
@ Tzorakoleftherakis I would greatly appreciate your kind help.I am trying to train 4 TD3 RL Agents in the Simulink Environment. Each Agent is supposed to control the output voltage of a Buck Converter by sending its action signal to the input of the Buck Converter (as a reference voltage). For the sake of improving the learning process and enhancing the exploration of the agents, I want to initiate the environment such that at the beginning of each training episode, the agents observe a new set of observations. The issue is that all 9 elements of the observation vectors depend on the output voltages of the Buck Converters (the Actions). So I need to initialize the model at the beginning of each training episode by initializing the inputs of the Buck Converters, then as the agent starts sampling from the environment, replace the initilizing parameters with the actions of the agents. To implement that, I have put the RL Agent blocks in the Triggered Subsystems, and connected their outputs to Swich Blocks for alternating between the initializing parameter and the output of Triggered Subsystems (Action Signals). from the beginning of the episode till the second 1 of the simulation, the model gets initialize with the initializing parameter, then in the second 1, switch will work, and triggered subsystem will be activated. My question is: How can I modify my code so that the agents start the learning process from seconde 1 till the end of simulation time at seconde 5 (4 seconds of training for each episode)?
@ Tzorakoleftherakis I would greatly appreciate your kind help. I am trying to train 4 TD3 RL Agents in the Simulink Environment. Each Agent is supposed to control the output voltage of a Buck Converter by sending its action signal to the input of the Buck Converter (as a reference voltage). For the sake of improving the learning process and enhancing the exploration of the agents, I want to initiate the environment such that at the beginning of each training episode, the agents observe a new set of observations. The issue is that all 9 elements of the observation vectors depend on the output voltages of the Buck Converters (the Actions). So I need to initialize the model at the beginning of each training episode by initializing the inputs of the Buck Converters, then as the agent starts sampling from the environment, replace the initilizing parameters with the actions of the agents. To implement that, I have put the RL Agent blocks in the Triggered Subsystems, and connected their outputs to Swich Blocks for alternating between the initializing parameter and the output of Triggered Subsystems (Action Signals). from the beginning of the episode till the second 1 of the simulation, the model gets initialize with the initializing parameter, then in the second 1, switch will work, and triggered subsystem will be activated. My question is: How can I modify my code so that the agents start the learning process from seconde 1 till the end of simulation time at seconde 5 (4 seconds of training for each episode)?
@ Tzorakoleftherakis I would greatly appreciate your kind help. reinforcement learning, td3 agents, buck converter, observation initilization MATLAB Answers — New Questions
​
Does the MATLAB Package Manager support proxy servers?
Does the MATLAB Package Manager (MPM) support downloading product files for MathWorks products through a proxy?Does the MATLAB Package Manager (MPM) support downloading product files for MathWorks products through a proxy? Does the MATLAB Package Manager (MPM) support downloading product files for MathWorks products through a proxy?  MATLAB Answers — New Questions
​
Why do I receive the error “Error: Download failed. Check the network connection and retry.” when installing using the MATLAB Package Manager?
When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
Error: Download failed. Check the network connection and retry.
How do I resolve this?When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
Error: Download failed. Check the network connection and retry.
How do I resolve this? When trying to install MathWorks products with the MATLAB Package Manager (MPM), I encounter an error like the following:
Error: Download failed. Check the network connection and retry.
How do I resolve this?  MATLAB Answers — New Questions
​
How to distinguish pressing cancel vs entering an empty string in inputdlg?
I have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
endI have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
end I have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
end inputdlg, matlab gui, input, loops MATLAB Answers — New Questions
​
What is MATLAB doing when adding multiple ZPK transfer functions together?
I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros)I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros)Â I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros) zpk, add MATLAB Answers — New Questions
​