Tag Archives: matlab
How to simulate permanent magnets using the PDE Toolbox in R2025a
I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox?I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox? I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox? pde, matlab code, mesh MATLAB Answers — New Questions
How can I plot multiple figures in one from multiple saved .fig files that have 2 figures but I only want 1 of them?
I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance!I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance! I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance! matlab, simulink, figure MATLAB Answers — New Questions
Characterize RC parameters of a battery cell.
Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do?Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do? Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do? battery, modelling MATLAB Answers — New Questions
multiplicationLayer – multiply by a constant
I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA!I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA! I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA! multiplicationlayer MATLAB Answers — New Questions
Running/testing scripts on multiple Matlab/Simulink versions?
I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier?I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier? I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier? version, bugs, release notes, bug reports MATLAB Answers — New Questions
Concatenation Error when using LSTM Layers in a Hybrid Actor (RL Toolbox)
Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks!Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks! Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks! rl-toolbox, lstm, concatenation MATLAB Answers — New Questions
Problem while running setup of Raspberry Pi Support Package
Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help!Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help! Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help! raspberry pi, system, path, packages, installation MATLAB Answers — New Questions
Update the content of a MatLab generated executable
I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome!I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome! I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome! matlab MATLAB Answers — New Questions
How to solve system of PDE’s using crank nicolson method to get graphical interpretations of equations? How to get skin friction and nusselt number using this code?
i have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B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aa(j+1,k)^2-2*aa(j+1,k)*aa(j,k))-Gr*bb(j,k)-Gs*cc(j,k)+M*aa(j,k);
r2(j,k)=(exp((-t(j)))/h)-(1/2*Pr*h^2)*(exp(-t(j+1))-2* exp(-t(j))+exp(-t(j-1)))-Df*(1/2*h^2)*(exp(-t(j+1))-2* exp(-t(j))…
+exp(-t(j-1)))+(bb(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold oni have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B=0; %B=0.0001;
Gr=2; %Gr=0.1=Delt. Gs=Dels
A=2; %A=alpha
Pr=5;
Gs=1; %3.5
Sc=1.5;
M=9; %M=30,12
Df=5;
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r*h^2)*(exp(-t(j+1))-2* exp(-t(j))+exp(-t(j-1)))-Df*(1/2*h^2)*(exp(-t(j+1))-2* exp(-t(j))…
+exp(-t(j-1)))+(bb(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on i have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B=0; %B=0.0001;
Gr=2; %Gr=0.1=Delt. Gs=Dels
A=2; %A=alpha
Pr=5;
Gs=1; %3.5
Sc=1.5;
M=9; %M=30,12
Df=5;
Sr=10;
Ec=0.1; % 0.01-0.1(0-1)
t(1)=0;
s(1)=0;
for j=2:n
t(j)=t(j-1)+h;
end
for j=2:n
s(j)=s(j-1)+m;
end
k=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(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on system of pde’s, crank nicloson method in matlab, skin friction and nusselt number MATLAB Answers — New Questions
Modbus RTU Write Simulink Block error
Hi community,
I am starting with the setup of a modbus RTU communication between my matlab simulink model and some surrounding devices. Using the new simulink block "modbus client read", I can read the register of my external device, which shows me, that I’ve created a stable communication. However, if I want to write a register on the device, using the block "modbus client write", I get the following error:
Error:An error occurred during simulation and the simulation was terminated
Caused by:
MATLAB System block ‘untitled/Modbus Client Write/internalModbus’ error occurred when invoking ‘stepImpl’ method of ‘icomm.system.ModbusWrite’. The error was thrown from ‘
‘C:Program FilesMATLABR2024btoolboxicommmodbusmodbusmodbusblks+icomm+systemModbusWrite.p’ at line 0′.
The Modbus server returned an invalid address error. Address + number of values to write is out of range.
The config of the write-block is pictured:
As aforementioned, it’s the same connection as used for the reading process. The model is quite simple and broken down to the minimum, but I get the error anyway:
Now I am struggling how to proceed with this error. Maybe someone can help me out!
Best
MarcoHi community,
I am starting with the setup of a modbus RTU communication between my matlab simulink model and some surrounding devices. Using the new simulink block "modbus client read", I can read the register of my external device, which shows me, that I’ve created a stable communication. However, if I want to write a register on the device, using the block "modbus client write", I get the following error:
Error:An error occurred during simulation and the simulation was terminated
Caused by:
MATLAB System block ‘untitled/Modbus Client Write/internalModbus’ error occurred when invoking ‘stepImpl’ method of ‘icomm.system.ModbusWrite’. The error was thrown from ‘
‘C:Program FilesMATLABR2024btoolboxicommmodbusmodbusmodbusblks+icomm+systemModbusWrite.p’ at line 0′.
The Modbus server returned an invalid address error. Address + number of values to write is out of range.
The config of the write-block is pictured:
As aforementioned, it’s the same connection as used for the reading process. The model is quite simple and broken down to the minimum, but I get the error anyway:
Now I am struggling how to proceed with this error. Maybe someone can help me out!
Best
Marco Hi community,
I am starting with the setup of a modbus RTU communication between my matlab simulink model and some surrounding devices. Using the new simulink block "modbus client read", I can read the register of my external device, which shows me, that I’ve created a stable communication. However, if I want to write a register on the device, using the block "modbus client write", I get the following error:
Error:An error occurred during simulation and the simulation was terminated
Caused by:
MATLAB System block ‘untitled/Modbus Client Write/internalModbus’ error occurred when invoking ‘stepImpl’ method of ‘icomm.system.ModbusWrite’. The error was thrown from ‘
‘C:Program FilesMATLABR2024btoolboxicommmodbusmodbusmodbusblks+icomm+systemModbusWrite.p’ at line 0′.
The Modbus server returned an invalid address error. Address + number of values to write is out of range.
The config of the write-block is pictured:
As aforementioned, it’s the same connection as used for the reading process. The model is quite simple and broken down to the minimum, but I get the error anyway:
Now I am struggling how to proceed with this error. Maybe someone can help me out!
Best
Marco simulink, modbus, modbusrtu, writeregister MATLAB Answers — New Questions
How to use the Visual Studio Code for Simulink c-caller Debugging with MATLAB Coder Interface?
I have installed the MATLAB Coder Interface for VSCode, (matlab-coder-interface-vscode-debugging.vsix) and I have the C-caller simulink function and I’d like to know how can I use this extension for C-caller c-function to debug it.
and this link "Simulate custom code in a separate process" is not clear to me how to use external tool (VSCode) and seprate process …
Please can you suggest the steps to use VS Code to debug the c-code for C-caller simulink funtion?
Thank you very much.I have installed the MATLAB Coder Interface for VSCode, (matlab-coder-interface-vscode-debugging.vsix) and I have the C-caller simulink function and I’d like to know how can I use this extension for C-caller c-function to debug it.
and this link "Simulate custom code in a separate process" is not clear to me how to use external tool (VSCode) and seprate process …
Please can you suggest the steps to use VS Code to debug the c-code for C-caller simulink funtion?
Thank you very much. I have installed the MATLAB Coder Interface for VSCode, (matlab-coder-interface-vscode-debugging.vsix) and I have the C-caller simulink function and I’d like to know how can I use this extension for C-caller c-function to debug it.
and this link "Simulate custom code in a separate process" is not clear to me how to use external tool (VSCode) and seprate process …
Please can you suggest the steps to use VS Code to debug the c-code for C-caller simulink funtion?
Thank you very much. vscode to debug simulink MATLAB Answers — New Questions
How to view a 3D Figure from “below”, e.g. z-axis facing downwards
I’m looking for a possibility to view/rotate a North-East-Down Coordinate Frame in a 3D Figure.
By casually plotting a cartesian coordinate system z is facing upwards, and by rotating it with the hand tool, it is not possible to "flip" the figure so that z is facing down.
If you set the z-Axis to ‘reverse’ the right hand system becomes a left-hand system, thus this is not a solution.
figure
plot3(0,0,0)
line([0 0.1],[0 0],[0 0],’LineWidth’,5,’DisplayName’,’X’)
line([0 0],[0 0.1],[0 0],’LineWidth’,5,’DisplayName’,’Y’)
line([0 0],[0 0],[0 0.1],’LineWidth’,5,’DisplayName’,’Z’)
legend
Take the above picture, I would like a solution where the Z-Line is Facing downwards, without changing the coordinate-systemI’m looking for a possibility to view/rotate a North-East-Down Coordinate Frame in a 3D Figure.
By casually plotting a cartesian coordinate system z is facing upwards, and by rotating it with the hand tool, it is not possible to "flip" the figure so that z is facing down.
If you set the z-Axis to ‘reverse’ the right hand system becomes a left-hand system, thus this is not a solution.
figure
plot3(0,0,0)
line([0 0.1],[0 0],[0 0],’LineWidth’,5,’DisplayName’,’X’)
line([0 0],[0 0.1],[0 0],’LineWidth’,5,’DisplayName’,’Y’)
line([0 0],[0 0],[0 0.1],’LineWidth’,5,’DisplayName’,’Z’)
legend
Take the above picture, I would like a solution where the Z-Line is Facing downwards, without changing the coordinate-system I’m looking for a possibility to view/rotate a North-East-Down Coordinate Frame in a 3D Figure.
By casually plotting a cartesian coordinate system z is facing upwards, and by rotating it with the hand tool, it is not possible to "flip" the figure so that z is facing down.
If you set the z-Axis to ‘reverse’ the right hand system becomes a left-hand system, thus this is not a solution.
figure
plot3(0,0,0)
line([0 0.1],[0 0],[0 0],’LineWidth’,5,’DisplayName’,’X’)
line([0 0],[0 0.1],[0 0],’LineWidth’,5,’DisplayName’,’Y’)
line([0 0],[0 0],[0 0.1],’LineWidth’,5,’DisplayName’,’Z’)
legend
Take the above picture, I would like a solution where the Z-Line is Facing downwards, without changing the coordinate-system ned, coordinatesystem, rotation MATLAB Answers — New Questions
Troubleshooting Signal Logging in SDI for FPGA Outputs in Speedgoat Motion Control HDL I/O Blockset
In pwm_example_hdlc.slx example from Speedgoat Motion Control HDL I/O Blockset v1.0 (R2024b). I want to view logged signals in SDI. There are PWM and CAP signals in the example which are set to logging.
I succesfully generated bitstream and run example on Speedgoat P3 Perfomance. The hardware generates PWM signals as expected (confirmed with oscilloscope). However, the SDI does not have any signal available during or post model execution.
During model build the following warning(s) is issued:
Warning: Unable to instrument ‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’: Unable to stream signal
‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’. Possible reasons include:
(1) Signal is not available in application.
(2) Signal does not use globally accessible memory in application.
(3) Signal connects to a MessageSend block.
(4) Signal has inherited sample time.
(5) Signal is discontiguous.
For more suggestions to resolve this issue, see Troubleshoot Signals for Streaming or File Log logging.
I followed the advice given in Troubleshoot Signals for Streaming or File Log logging and in this post:
added test point
added Signal Copy Block
made PWM_A signal globally accessible
But the issue persist and no data appears in SDI (external mode, command line, slrtExplorer).
If I add the rate transition block, the signal appear in SDI, however the value is 0 (Output port sample time is 1e-4s), whereas PWM perion is 1e-3s.
If I add sine generator block in the model and log its output, this sine output signal appears in SDI as expected.
What can be the reason that the outputs from FPGA cannot be visualized in the model?In pwm_example_hdlc.slx example from Speedgoat Motion Control HDL I/O Blockset v1.0 (R2024b). I want to view logged signals in SDI. There are PWM and CAP signals in the example which are set to logging.
I succesfully generated bitstream and run example on Speedgoat P3 Perfomance. The hardware generates PWM signals as expected (confirmed with oscilloscope). However, the SDI does not have any signal available during or post model execution.
During model build the following warning(s) is issued:
Warning: Unable to instrument ‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’: Unable to stream signal
‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’. Possible reasons include:
(1) Signal is not available in application.
(2) Signal does not use globally accessible memory in application.
(3) Signal connects to a MessageSend block.
(4) Signal has inherited sample time.
(5) Signal is discontiguous.
For more suggestions to resolve this issue, see Troubleshoot Signals for Streaming or File Log logging.
I followed the advice given in Troubleshoot Signals for Streaming or File Log logging and in this post:
added test point
added Signal Copy Block
made PWM_A signal globally accessible
But the issue persist and no data appears in SDI (external mode, command line, slrtExplorer).
If I add the rate transition block, the signal appear in SDI, however the value is 0 (Output port sample time is 1e-4s), whereas PWM perion is 1e-3s.
If I add sine generator block in the model and log its output, this sine output signal appears in SDI as expected.
What can be the reason that the outputs from FPGA cannot be visualized in the model? In pwm_example_hdlc.slx example from Speedgoat Motion Control HDL I/O Blockset v1.0 (R2024b). I want to view logged signals in SDI. There are PWM and CAP signals in the example which are set to logging.
I succesfully generated bitstream and run example on Speedgoat P3 Perfomance. The hardware generates PWM signals as expected (confirmed with oscilloscope). However, the SDI does not have any signal available during or post model execution.
During model build the following warning(s) is issued:
Warning: Unable to instrument ‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’: Unable to stream signal
‘gm_pwm_example_hdlc_slrt/DUT PWM and CAP/DataTypeConversion:1’. Possible reasons include:
(1) Signal is not available in application.
(2) Signal does not use globally accessible memory in application.
(3) Signal connects to a MessageSend block.
(4) Signal has inherited sample time.
(5) Signal is discontiguous.
For more suggestions to resolve this issue, see Troubleshoot Signals for Streaming or File Log logging.
I followed the advice given in Troubleshoot Signals for Streaming or File Log logging and in this post:
added test point
added Signal Copy Block
made PWM_A signal globally accessible
But the issue persist and no data appears in SDI (external mode, command line, slrtExplorer).
If I add the rate transition block, the signal appear in SDI, however the value is 0 (Output port sample time is 1e-4s), whereas PWM perion is 1e-3s.
If I add sine generator block in the model and log its output, this sine output signal appears in SDI as expected.
What can be the reason that the outputs from FPGA cannot be visualized in the model? real-time, speedgoat, sdi MATLAB Answers — New Questions
Simulating Induction motor inter-turn short circuit faults
Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested.Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested. Hi! Using Simulink / Simscape I wish to Simulate an Induction Motor for getting normal operation and inter-turn short circuit fault data for training my Machine learning based fault classifier. I basically desire a model that incorporates saturation and iron losses effects as well. Any help and guidance is requested. induction-motor model, simulink, simscape MATLAB Answers — New Questions
Assigning plot to an existing axes Matlab GUI
Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint?Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint? Hi,
I have a GUI in Matlab and several functions in it. One function is for plotting a figure, I need to assign it to an existing axes in GUI. I have tried several options, nothing has worked out yet.
Code below is the current option I had tried before I asked here.
set(‘CurrentAxes’,’axes11′)
plot(VyQRS(:,2));
grid on
The plot of VyQRS I need to assign to axes11.
Could you please give me any hint? matlab gui, plotting, guide MATLAB Answers — New Questions
Construction of subplots for the comparison of two models
Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard,Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard, Hi Everyone!
I would like to know what kind of subplot (code) I could use to make similar graphics.
Best regard, two mdels comparison, comparison models MATLAB Answers — New Questions
Execution times and the “pause” function
I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds.I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds. I have a question about a strange phenomenon I have been noticing for some time whilst working with Matlab and which has now become somewhat acute.
When I run scripts which are relatively demanding on my computer, pausing and immediately unpausing the execution weirdly appears to speed up the execution of the rest of the script.
The current example is this:
I am running a simulation model, which is essentially just one big loop representing simulation periods . Within this loop there is another loop which is entered only under a certain condition. If this second loop is entered in some simulation period t, the simualtion of this particular period naturally takes longer than that of the other ones as more operations are executed.
Essentially the programm looks like this:
for t=1:T
do stuff
if condition holds
for tt=1:TT
do more stuff
end
end
end
The problem I have is the following: After the second, inner loop is entered, all following simulation periods take longer to execute, even when the condition does not hold. I have gone into debug mode and can 100% confirm that the second loop is not entered in other simulation periods. Nevertheless those periods take longer to execute after the second loop has been entered once in a previous period.
Additionally, if i pause the execution of the script manually after the second loop has been entered and exited again and then continue, the script speeds back up and the rest of the periods are simulated at the usual speed. More generally, I often find that if a script runs slowly I can speed it up significantly by pausing and unpausing.
Does anyone know what might be causing this?
PS: After some additonal experimentation it seems that this phenomenon only occurs if I click the pause button in the GUI, i.e. if I enter debug mode and then pess continue. Simply inserting pause(n) under some condition into the script does not cause this change in execution speeds. execution time, pause, loops MATLAB Answers — New Questions
finding local maximum/minimum for a function
how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4 how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4 matlab, maxima MATLAB Answers — New Questions
How to reduce current ripple in a closed loop buck converter for a PV li-ion battery charger??
If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks.If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks. If i test the buck converter model alone i get a smooth current and voltage signal,
but when i add the battery and the control logic, the current signal has a very high peak to peak amplitude.
Do you know why us this behavior??
Thanks. li-ion, battery charger, buck converter, solar energy, current ripple, power_electronics_control, battery_system_management MATLAB Answers — New Questions
Passing data by reference to Matlab toolbox functions for code generation
Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization.Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization. Hello everyone.
I am working on optimization of generated code. My algorithm uses toolbox function interp1 for linear interpolation. Code for it is generated by Matlab embedded coder. I want to prevent copying of input arrays to it. Normally function doesn’t define input argument as in/out, but algorithm doesn’t use them afterwards and copy is redundant. Is there a way to tell Matlab coder about it to do optimization. matlab coder, memory, embedded coder MATLAB Answers — New Questions