Category: Matlab
Category Archives: Matlab
Problem in running python function from MATLAB console
Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b.Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b. Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b. matlab – python, arrays, function MATLAB Answers — New Questions
How to connect PEM Fuel Cell with Battery, vary hydrogen flow rate, and plot hydrogen consumption vs time in Simulink?
Hello,
I am working on a PEM Fuel Cell + Battery hybrid model in Simulink for a UAV application. I have attached two screenshots of my current model (Fuel Cell stack with inputs and the Battery block).
I have a few specific questions:
Connecting Fuel Cell and Battery
I want to connect the black Fuel Cell stack (with hydrogen, air, and thermal inputs) to the blue Battery and DC system blocks (as shown in my screenshots).
What is the correct way to connect them together? Should I use a DC-DC converter in between, or can I directly connect them?
Varying Hydrogen Flow Rate
Currently, I am providing constant values for pfuel, qfuel, pair, and qair.
How can I make qfuel (hydrogen flow rate) time-varying instead of constant? For example, decreasing with time or following a load demand profile.
Hydrogen Consumption vs Time Graph
I want to plot the hydrogen consumption vs time (i.e., how much hydrogen is used and at what time it is consumed).
Is there any built-in output port in the Fuel Cell stack block that gives hydrogen consumption directly?
Or should I calculate hydrogen consumption from qfuel flow rate input over simulation time?
Parameter Values
I am not fully sure about the typical values for hydrogen flow rate (qfuel), air flow rate (qair), and pressures (pfuel, pair) for a small PEM Fuel Cell stack (like 35 cells, area 9 cm²).
Can you please suggest what values are normally used in Simulink models for these inputs?
Any guidance or example models would be really helpful.
Thanks in advance!Hello,
I am working on a PEM Fuel Cell + Battery hybrid model in Simulink for a UAV application. I have attached two screenshots of my current model (Fuel Cell stack with inputs and the Battery block).
I have a few specific questions:
Connecting Fuel Cell and Battery
I want to connect the black Fuel Cell stack (with hydrogen, air, and thermal inputs) to the blue Battery and DC system blocks (as shown in my screenshots).
What is the correct way to connect them together? Should I use a DC-DC converter in between, or can I directly connect them?
Varying Hydrogen Flow Rate
Currently, I am providing constant values for pfuel, qfuel, pair, and qair.
How can I make qfuel (hydrogen flow rate) time-varying instead of constant? For example, decreasing with time or following a load demand profile.
Hydrogen Consumption vs Time Graph
I want to plot the hydrogen consumption vs time (i.e., how much hydrogen is used and at what time it is consumed).
Is there any built-in output port in the Fuel Cell stack block that gives hydrogen consumption directly?
Or should I calculate hydrogen consumption from qfuel flow rate input over simulation time?
Parameter Values
I am not fully sure about the typical values for hydrogen flow rate (qfuel), air flow rate (qair), and pressures (pfuel, pair) for a small PEM Fuel Cell stack (like 35 cells, area 9 cm²).
Can you please suggest what values are normally used in Simulink models for these inputs?
Any guidance or example models would be really helpful.
Thanks in advance! Hello,
I am working on a PEM Fuel Cell + Battery hybrid model in Simulink for a UAV application. I have attached two screenshots of my current model (Fuel Cell stack with inputs and the Battery block).
I have a few specific questions:
Connecting Fuel Cell and Battery
I want to connect the black Fuel Cell stack (with hydrogen, air, and thermal inputs) to the blue Battery and DC system blocks (as shown in my screenshots).
What is the correct way to connect them together? Should I use a DC-DC converter in between, or can I directly connect them?
Varying Hydrogen Flow Rate
Currently, I am providing constant values for pfuel, qfuel, pair, and qair.
How can I make qfuel (hydrogen flow rate) time-varying instead of constant? For example, decreasing with time or following a load demand profile.
Hydrogen Consumption vs Time Graph
I want to plot the hydrogen consumption vs time (i.e., how much hydrogen is used and at what time it is consumed).
Is there any built-in output port in the Fuel Cell stack block that gives hydrogen consumption directly?
Or should I calculate hydrogen consumption from qfuel flow rate input over simulation time?
Parameter Values
I am not fully sure about the typical values for hydrogen flow rate (qfuel), air flow rate (qair), and pressures (pfuel, pair) for a small PEM Fuel Cell stack (like 35 cells, area 9 cm²).
Can you please suggest what values are normally used in Simulink models for these inputs?
Any guidance or example models would be really helpful.
Thanks in advance! pemfc, battery, uav MATLAB Answers — New Questions
Single Precision Converter Does not work with R2016B
I am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciatedI am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciated I am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciated single precision converter r2016b MATLAB Answers — New Questions
When I use MATLAB’s export image feature, I name the file “untietled” and all other names, MATLAB crashes and automatically quits
When I use MATLAB’s export image feature, I name the file "untietled" and all other names, MATLAB crashes and automatically quitsWhen I use MATLAB’s export image feature, I name the file "untietled" and all other names, MATLAB crashes and automatically quits When I use MATLAB’s export image feature, I name the file "untietled" and all other names, MATLAB crashes and automatically quits matlab MATLAB Answers — New Questions
Generation of proto and thunk files for distribution
We are looking for the leanest way to generate prototype and thunk files for a library we distribute to Matlab users. In our CI/CD process, we use Docker containers for building our libraries and would like to include the generation of Matlab proto and thunk files in the CI/CD process. Is there a way to generate these files without a full installation of Matlab? Is there a perl script or some other mechanism supporting this process?We are looking for the leanest way to generate prototype and thunk files for a library we distribute to Matlab users. In our CI/CD process, we use Docker containers for building our libraries and would like to include the generation of Matlab proto and thunk files in the CI/CD process. Is there a way to generate these files without a full installation of Matlab? Is there a perl script or some other mechanism supporting this process? We are looking for the leanest way to generate prototype and thunk files for a library we distribute to Matlab users. In our CI/CD process, we use Docker containers for building our libraries and would like to include the generation of Matlab proto and thunk files in the CI/CD process. Is there a way to generate these files without a full installation of Matlab? Is there a perl script or some other mechanism supporting this process? thunk, proto, loadlibrary MATLAB Answers — New Questions
Run matlab script on remote windows computer using cmd
Hello,
I am trying to run several different MATLAB scripts on a remote windows computer to aggregate data from various sensors. How can I start a matlab script from cmd over ssh? I have tried matlab -nodesktop -noFigureWindows -nosplash -r "myscript; exit", but the script never runs.Hello,
I am trying to run several different MATLAB scripts on a remote windows computer to aggregate data from various sensors. How can I start a matlab script from cmd over ssh? I have tried matlab -nodesktop -noFigureWindows -nosplash -r "myscript; exit", but the script never runs. Hello,
I am trying to run several different MATLAB scripts on a remote windows computer to aggregate data from various sensors. How can I start a matlab script from cmd over ssh? I have tried matlab -nodesktop -noFigureWindows -nosplash -r "myscript; exit", but the script never runs. remote, windows, ros2, cmd MATLAB Answers — New Questions
Simulink FMI 3.0 Binary data
I’m currently testing the importing of a FMU v3.0 (Co-Simulation) in Simulink, which is supported since R2023b. In the 3.0 specification, binary data is supported as a new data type. I have a simple test FMU with an binary output signal, which is recognized when importing the FMU aswell as the data type "FMUBinary".
The model runs without any array error and the Float64Output behaves like expected. But when I try to connect the signal with any other block, like, for example a MATLAB function to do some calculations with the data, I get the error message:
Error:The ‘SubSystem’ block cannot accept a signal of type FMUBinary. A signal of type FMUBinary is connected to ‘Input Port 1’ of block ‘DynamicArray/MATLAB Function’.
Does some know how to handle this FMUBinary data type? Thanks in advance!I’m currently testing the importing of a FMU v3.0 (Co-Simulation) in Simulink, which is supported since R2023b. In the 3.0 specification, binary data is supported as a new data type. I have a simple test FMU with an binary output signal, which is recognized when importing the FMU aswell as the data type "FMUBinary".
The model runs without any array error and the Float64Output behaves like expected. But when I try to connect the signal with any other block, like, for example a MATLAB function to do some calculations with the data, I get the error message:
Error:The ‘SubSystem’ block cannot accept a signal of type FMUBinary. A signal of type FMUBinary is connected to ‘Input Port 1’ of block ‘DynamicArray/MATLAB Function’.
Does some know how to handle this FMUBinary data type? Thanks in advance! I’m currently testing the importing of a FMU v3.0 (Co-Simulation) in Simulink, which is supported since R2023b. In the 3.0 specification, binary data is supported as a new data type. I have a simple test FMU with an binary output signal, which is recognized when importing the FMU aswell as the data type "FMUBinary".
The model runs without any array error and the Float64Output behaves like expected. But when I try to connect the signal with any other block, like, for example a MATLAB function to do some calculations with the data, I get the error message:
Error:The ‘SubSystem’ block cannot accept a signal of type FMUBinary. A signal of type FMUBinary is connected to ‘Input Port 1’ of block ‘DynamicArray/MATLAB Function’.
Does some know how to handle this FMUBinary data type? Thanks in advance! fmi, fmi 3.0, binary data, simulink, fmu import, r2023b MATLAB Answers — New Questions
Suppress Simulink build summary in command window
Is there a way to suppress the Simulink build summary (running in accelerator mode) in the command window. For example, is there way to stop this printing out:? My model is composed of multiple sub-models using model references.Is there a way to suppress the Simulink build summary (running in accelerator mode) in the command window. For example, is there way to stop this printing out:? My model is composed of multiple sub-models using model references. Is there a way to suppress the Simulink build summary (running in accelerator mode) in the command window. For example, is there way to stop this printing out:? My model is composed of multiple sub-models using model references. build summary, command window, simulink MATLAB Answers — New Questions
UI scaling changes from latest 2025a prerelease to official 2025a release
Hi, I spent MANY hours to get my GUI running in 2025a – I included many changes to fix all the scaling issues of ui elements. I was always using the latest prerelease to implement and test these changes. Now after the "big mathworks crash", I finally could download the official 2025a release. And I notice that the scaling of ui element has completely changed and everything is messed up again. This is driving me crazy! Why are there prereleases if things are again changed in the last second?
I hope this is just a dpi scaling thing that can be fixed easily. Anyone maybe with some hints where to search?
Thanks!Hi, I spent MANY hours to get my GUI running in 2025a – I included many changes to fix all the scaling issues of ui elements. I was always using the latest prerelease to implement and test these changes. Now after the "big mathworks crash", I finally could download the official 2025a release. And I notice that the scaling of ui element has completely changed and everything is messed up again. This is driving me crazy! Why are there prereleases if things are again changed in the last second?
I hope this is just a dpi scaling thing that can be fixed easily. Anyone maybe with some hints where to search?
Thanks! Hi, I spent MANY hours to get my GUI running in 2025a – I included many changes to fix all the scaling issues of ui elements. I was always using the latest prerelease to implement and test these changes. Now after the "big mathworks crash", I finally could download the official 2025a release. And I notice that the scaling of ui element has completely changed and everything is messed up again. This is driving me crazy! Why are there prereleases if things are again changed in the last second?
I hope this is just a dpi scaling thing that can be fixed easily. Anyone maybe with some hints where to search?
Thanks! matlab, gui, pivlab MATLAB Answers — New Questions
Does MATLAB work on any Cloud Computing Service?
Will MATLAB work on Google Cloud Platform or Amazon Web Services and licensing be an issue or can our current concurrent license #47069 still be used?Will MATLAB work on Google Cloud Platform or Amazon Web Services and licensing be an issue or can our current concurrent license #47069 still be used? Will MATLAB work on Google Cloud Platform or Amazon Web Services and licensing be an issue or can our current concurrent license #47069 still be used? cloud computing MATLAB Answers — New Questions
Creating a string for loop.
Hi, I’m trying to simplify my code. Right now I have my code set up like this:
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mb = sum(in_mb)/(length(in_mb))
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mcup = sum(in_mcup)/(length(in_mcup))
Percentageoftimein_mclow = sum(in_mclow)/(length(in_mclow))
Percentageoftimein_bof = sum(in_bof)/(length(in_bof))
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
I feel like I should be able to simplify this into a loop then adding my last line after the loop like this:
names ={‘in_cob’,’in_mb’,’in_mp’,’in_mcup’,’in_mclow’,’in_bof’}
for 1:length(names)
Percentageoftime+names = sum(names)/(length(names))
end
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
But I keep getting this error when I try:
% File: plot_smolts.m Line: 91 Column: 9
% Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
% syntax error. To construct matrices, use brackets instead of parentheses.
Not sure how I should go about doing this.Hi, I’m trying to simplify my code. Right now I have my code set up like this:
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mb = sum(in_mb)/(length(in_mb))
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mcup = sum(in_mcup)/(length(in_mcup))
Percentageoftimein_mclow = sum(in_mclow)/(length(in_mclow))
Percentageoftimein_bof = sum(in_bof)/(length(in_bof))
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
I feel like I should be able to simplify this into a loop then adding my last line after the loop like this:
names ={‘in_cob’,’in_mb’,’in_mp’,’in_mcup’,’in_mclow’,’in_bof’}
for 1:length(names)
Percentageoftime+names = sum(names)/(length(names))
end
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
But I keep getting this error when I try:
% File: plot_smolts.m Line: 91 Column: 9
% Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
% syntax error. To construct matrices, use brackets instead of parentheses.
Not sure how I should go about doing this. Hi, I’m trying to simplify my code. Right now I have my code set up like this:
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mb = sum(in_mb)/(length(in_mb))
Percentageoftimein_mp = sum(in_mp)/(length(in_mp))
Percentageoftimein_mcup = sum(in_mcup)/(length(in_mcup))
Percentageoftimein_mclow = sum(in_mclow)/(length(in_mclow))
Percentageoftimein_bof = sum(in_bof)/(length(in_bof))
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
I feel like I should be able to simplify this into a loop then adding my last line after the loop like this:
names ={‘in_cob’,’in_mb’,’in_mp’,’in_mcup’,’in_mclow’,’in_bof’}
for 1:length(names)
Percentageoftime+names = sum(names)/(length(names))
end
Percentageoftimein_mc = PercentageoftimeinMClow+PercentageoftimeinMCup ;
But I keep getting this error when I try:
% File: plot_smolts.m Line: 91 Column: 9
% Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
% syntax error. To construct matrices, use brackets instead of parentheses.
Not sure how I should go about doing this. strings, for loop MATLAB Answers — New Questions
how to control the BackgroundAlpha of the text box
Is there a way to create a text box with BackgroundAlpha (such as 0.5)? I can’t find the alpha option for text box background in Text Properties.Is there a way to create a text box with BackgroundAlpha (such as 0.5)? I can’t find the alpha option for text box background in Text Properties. Is there a way to create a text box with BackgroundAlpha (such as 0.5)? I can’t find the alpha option for text box background in Text Properties. text MATLAB Answers — New Questions
Modelling a Pressure Regulator in Simscape
Hi, I am trying to model a pressure regulator in simspace, but I could not manage to connect mechanical system to fluid system. I used single acting actuator and connect it to matlab function that has a function form all the "to workspace" blocks how can I fix the system I attached the picture of the systems.
% Compute spring force (negative due to opposing motion)
F_spring = -x * (k1 + k2) + F_preload;
% Compute pressure forces
F_pressure = P_out * A_outlet + P_atm * A_atm – P_sen * A_sen – P_in * A_inlet;
% Compute friction force
F_piston = mu * A_pis * P_sen;
F_poppet = mu * A_pop * P_in;
F_friction = sign(v) * (F_piston + F_poppet);
% Net force (sum of spring, pressure, and friction forces)
F_net = F_spring + F_pressure – F_friction;
% Note: m_tot * x_ddot = F_net should be solved externally (e.g., in Simulink)
endHi, I am trying to model a pressure regulator in simspace, but I could not manage to connect mechanical system to fluid system. I used single acting actuator and connect it to matlab function that has a function form all the "to workspace" blocks how can I fix the system I attached the picture of the systems.
% Compute spring force (negative due to opposing motion)
F_spring = -x * (k1 + k2) + F_preload;
% Compute pressure forces
F_pressure = P_out * A_outlet + P_atm * A_atm – P_sen * A_sen – P_in * A_inlet;
% Compute friction force
F_piston = mu * A_pis * P_sen;
F_poppet = mu * A_pop * P_in;
F_friction = sign(v) * (F_piston + F_poppet);
% Net force (sum of spring, pressure, and friction forces)
F_net = F_spring + F_pressure – F_friction;
% Note: m_tot * x_ddot = F_net should be solved externally (e.g., in Simulink)
end Hi, I am trying to model a pressure regulator in simspace, but I could not manage to connect mechanical system to fluid system. I used single acting actuator and connect it to matlab function that has a function form all the "to workspace" blocks how can I fix the system I attached the picture of the systems.
% Compute spring force (negative due to opposing motion)
F_spring = -x * (k1 + k2) + F_preload;
% Compute pressure forces
F_pressure = P_out * A_outlet + P_atm * A_atm – P_sen * A_sen – P_in * A_inlet;
% Compute friction force
F_piston = mu * A_pis * P_sen;
F_poppet = mu * A_pop * P_in;
F_friction = sign(v) * (F_piston + F_poppet);
% Net force (sum of spring, pressure, and friction forces)
F_net = F_spring + F_pressure – F_friction;
% Note: m_tot * x_ddot = F_net should be solved externally (e.g., in Simulink)
end simulink, simscape MATLAB Answers — New Questions
save a cmyk image in jpeg
hi
i would like to save a cmyk image in jpeg
thanks!hi
i would like to save a cmyk image in jpeg
thanks! hi
i would like to save a cmyk image in jpeg
thanks! cmyk image, jpeg MATLAB Answers — New Questions
How can I pass a tunable struct parameter as an input to the generated step function in Embedded Coder for a Simulink model using reusable function packaging?
Hello MathWorks team,
I have a Simulink model named experiment_demo.slx that includes a MATLAB Function block with the following code:
function adjusted_setpoint = fcn(setpoint, cfg)
adjusted_setpoint = setpoint * cfg.gain * cfg.offset;
setpoint is provided via an Inport.
cfg is a tunable parameter defined as a Simulink.Parameter with a Bus type (ModelConfigBus) and configured via the Model Explorer.
Model configuration:
Solver: Fixed-step
Code Generation:
System target file: ert.tlc
Code interface packaging: Reusable function
Code is generated using Embedded Coder. In the generated code:
The ModelConfigBus struct is defined in experiment_demo_types.h as:
typedef struct {
real_T gain;
real_T offset;
} ModelConfigBus;
My goal is to pass the cfg parameter directly into the generated experiment_demo_step() function, so that it can be configured from an external source (e.g., another module or application). Ideally, I would like the struct to be declared in experiment_demo.h and used as an input argument in experiment_demo.c.
Questions:
What is the recommended way to expose a tunable struct parameter like cfg as an input to the step() function in the generated code?
Is there a configuration or customization (e.g., via code interface settings or TLC customization) that allows this struct to be passed explicitly to the step function?
Would moving the struct definition from experiment_demo_types.h to experiment_demo.h be supported or recommended for this use case?
Thank you!Hello MathWorks team,
I have a Simulink model named experiment_demo.slx that includes a MATLAB Function block with the following code:
function adjusted_setpoint = fcn(setpoint, cfg)
adjusted_setpoint = setpoint * cfg.gain * cfg.offset;
setpoint is provided via an Inport.
cfg is a tunable parameter defined as a Simulink.Parameter with a Bus type (ModelConfigBus) and configured via the Model Explorer.
Model configuration:
Solver: Fixed-step
Code Generation:
System target file: ert.tlc
Code interface packaging: Reusable function
Code is generated using Embedded Coder. In the generated code:
The ModelConfigBus struct is defined in experiment_demo_types.h as:
typedef struct {
real_T gain;
real_T offset;
} ModelConfigBus;
My goal is to pass the cfg parameter directly into the generated experiment_demo_step() function, so that it can be configured from an external source (e.g., another module or application). Ideally, I would like the struct to be declared in experiment_demo.h and used as an input argument in experiment_demo.c.
Questions:
What is the recommended way to expose a tunable struct parameter like cfg as an input to the step() function in the generated code?
Is there a configuration or customization (e.g., via code interface settings or TLC customization) that allows this struct to be passed explicitly to the step function?
Would moving the struct definition from experiment_demo_types.h to experiment_demo.h be supported or recommended for this use case?
Thank you! Hello MathWorks team,
I have a Simulink model named experiment_demo.slx that includes a MATLAB Function block with the following code:
function adjusted_setpoint = fcn(setpoint, cfg)
adjusted_setpoint = setpoint * cfg.gain * cfg.offset;
setpoint is provided via an Inport.
cfg is a tunable parameter defined as a Simulink.Parameter with a Bus type (ModelConfigBus) and configured via the Model Explorer.
Model configuration:
Solver: Fixed-step
Code Generation:
System target file: ert.tlc
Code interface packaging: Reusable function
Code is generated using Embedded Coder. In the generated code:
The ModelConfigBus struct is defined in experiment_demo_types.h as:
typedef struct {
real_T gain;
real_T offset;
} ModelConfigBus;
My goal is to pass the cfg parameter directly into the generated experiment_demo_step() function, so that it can be configured from an external source (e.g., another module or application). Ideally, I would like the struct to be declared in experiment_demo.h and used as an input argument in experiment_demo.c.
Questions:
What is the recommended way to expose a tunable struct parameter like cfg as an input to the step() function in the generated code?
Is there a configuration or customization (e.g., via code interface settings or TLC customization) that allows this struct to be passed explicitly to the step function?
Would moving the struct definition from experiment_demo_types.h to experiment_demo.h be supported or recommended for this use case?
Thank you! simulink, embeddedcoder, reusablefunction MATLAB Answers — New Questions
Multiple Instances of MATLAB operating on Simulink Data Dictionaries can lead to crash or errors “database slddc is locked”
I am running multiple MATLAB instance on my machine that operate on Simulink Data Dictionaries. This could be either:Multiple MATLAB’s started at the same time by calling the matlab executable in a batch or similar script. Multiple MATLAB workers using parfeval, parfor, etc and doing Simulink Data Dictionary operations on these workers.
In some cases I get this error:
The database \?C:UsersrspenceAppDataLocalTempdata_model_repository3.4_R2023b_v1_rspence.slddc is locked, or a table in the database is locked. (database is locked)
In other cases I get a MATLAB Crash where the stacktrace points to something in Simulink Data Dictionary.
What could be the cause?I am running multiple MATLAB instance on my machine that operate on Simulink Data Dictionaries. This could be either:Multiple MATLAB’s started at the same time by calling the matlab executable in a batch or similar script. Multiple MATLAB workers using parfeval, parfor, etc and doing Simulink Data Dictionary operations on these workers.
In some cases I get this error:
The database \?C:UsersrspenceAppDataLocalTempdata_model_repository3.4_R2023b_v1_rspence.slddc is locked, or a table in the database is locked. (database is locked)
In other cases I get a MATLAB Crash where the stacktrace points to something in Simulink Data Dictionary.
What could be the cause? I am running multiple MATLAB instance on my machine that operate on Simulink Data Dictionaries. This could be either:Multiple MATLAB’s started at the same time by calling the matlab executable in a batch or similar script. Multiple MATLAB workers using parfeval, parfor, etc and doing Simulink Data Dictionary operations on these workers.
In some cases I get this error:
The database \?C:UsersrspenceAppDataLocalTempdata_model_repository3.4_R2023b_v1_rspence.slddc is locked, or a table in the database is locked. (database is locked)
In other cases I get a MATLAB Crash where the stacktrace points to something in Simulink Data Dictionary.
What could be the cause? MATLAB Answers — New Questions
uifigure+uitree, multiple selected nodes
Hello,
Does anybody know a (undocumented) workaround to have multiple nodes selected in a uitree with checkboxes? I like to distinguish between checked and selected items.
If the uitree component is used without checkboxes it is possible. I am wondering why this is not implemented (yet)…
hF = uifigure();
hT = uitree(hF,’checkbox’);
hO1 = uitreenode(Parent=hT, Text=’object1′);
hO2 = uitreenode(Parent=hT, Text=’object2′);
hO3 = uitreenode(Parent=hT, Text=’object3′);
hO4 = uitreenode(Parent=hT, Text=’object4′);
hT.CheckedNodes = [hO1, hO2];
hT.SelectedNodes = [hO3, hO4];
%Error using matlab.ui.container.internal.model.TreeComponent/set.SelectedNodes (line 161)
%’SelectedNodes’ must be an empty array or a 1-by-1 TreeNode object that is a child in the CheckBoxTree.
Thanks in advance,
MartinHello,
Does anybody know a (undocumented) workaround to have multiple nodes selected in a uitree with checkboxes? I like to distinguish between checked and selected items.
If the uitree component is used without checkboxes it is possible. I am wondering why this is not implemented (yet)…
hF = uifigure();
hT = uitree(hF,’checkbox’);
hO1 = uitreenode(Parent=hT, Text=’object1′);
hO2 = uitreenode(Parent=hT, Text=’object2′);
hO3 = uitreenode(Parent=hT, Text=’object3′);
hO4 = uitreenode(Parent=hT, Text=’object4′);
hT.CheckedNodes = [hO1, hO2];
hT.SelectedNodes = [hO3, hO4];
%Error using matlab.ui.container.internal.model.TreeComponent/set.SelectedNodes (line 161)
%’SelectedNodes’ must be an empty array or a 1-by-1 TreeNode object that is a child in the CheckBoxTree.
Thanks in advance,
Martin Hello,
Does anybody know a (undocumented) workaround to have multiple nodes selected in a uitree with checkboxes? I like to distinguish between checked and selected items.
If the uitree component is used without checkboxes it is possible. I am wondering why this is not implemented (yet)…
hF = uifigure();
hT = uitree(hF,’checkbox’);
hO1 = uitreenode(Parent=hT, Text=’object1′);
hO2 = uitreenode(Parent=hT, Text=’object2′);
hO3 = uitreenode(Parent=hT, Text=’object3′);
hO4 = uitreenode(Parent=hT, Text=’object4′);
hT.CheckedNodes = [hO1, hO2];
hT.SelectedNodes = [hO3, hO4];
%Error using matlab.ui.container.internal.model.TreeComponent/set.SelectedNodes (line 161)
%’SelectedNodes’ must be an empty array or a 1-by-1 TreeNode object that is a child in the CheckBoxTree.
Thanks in advance,
Martin uifigure, uitree, selectednodes MATLAB Answers — New Questions
MATLAB graph/cyclebasis: How can I extract labeling-independent “minimal loop units”?
I have two undirected graphs that represent the same connectivity (isomorphic up to node relabeling). When I call cyclebasis on each, I get different sets of cycles. I understand a cycle basis can depend on the spanning tree/edge order, but I want a labeling-invariant notion of “minimal loop units.”
Code
clc; clear; close all
node = [
2 7
2 3
3 4
4 5
5 6
6 1
1 4
1 5
3 6
1 3
5 7
6 7
2 6
5 8];
G = graph(node(:,1), node(:,2), []);
cycles = cyclebasis(G)
figure(1); plot(G,’Layout’,’force’);
%%
node2 = [
1 2
2 3
3 4
4 1
1 5
5 6
2 4
6 7
3 6
2 5
3 7
4 7
2 6
6 8];
G2 = graph(node2(:,1), node2(:,2), []);
cycles2 = cyclebasis(G2)
figure(2); plot(G2,’Layout’,’force’);
Result:
cycles =
7×1 cell array
{[1 3 6 5]}
{[ 1 4 5]}
{[ 1 5 6]}
{[ 2 3 6]}
{[2 6 5 7]}
{[3 4 5 6]}
{[ 5 6 7]}
cycles2 =
7×1 cell array
{[ 1 2 4]}
{[ 1 2 5]}
{[ 2 3 4]}
{[ 2 3 6]}
{[2 3 7 6]}
{[2 4 7 6]}
{[ 2 5 6]}
Questions:
I know cyclebasis can vary with spanning tree/edge ordering. What’s the recommended way in MATLAB to obtain “minimal loop units” that do not depend on node labeling or edge input order? For example, in the above case, each cycle is a 3-node triangle, and there should be seven such cycles.I have two undirected graphs that represent the same connectivity (isomorphic up to node relabeling). When I call cyclebasis on each, I get different sets of cycles. I understand a cycle basis can depend on the spanning tree/edge order, but I want a labeling-invariant notion of “minimal loop units.”
Code
clc; clear; close all
node = [
2 7
2 3
3 4
4 5
5 6
6 1
1 4
1 5
3 6
1 3
5 7
6 7
2 6
5 8];
G = graph(node(:,1), node(:,2), []);
cycles = cyclebasis(G)
figure(1); plot(G,’Layout’,’force’);
%%
node2 = [
1 2
2 3
3 4
4 1
1 5
5 6
2 4
6 7
3 6
2 5
3 7
4 7
2 6
6 8];
G2 = graph(node2(:,1), node2(:,2), []);
cycles2 = cyclebasis(G2)
figure(2); plot(G2,’Layout’,’force’);
Result:
cycles =
7×1 cell array
{[1 3 6 5]}
{[ 1 4 5]}
{[ 1 5 6]}
{[ 2 3 6]}
{[2 6 5 7]}
{[3 4 5 6]}
{[ 5 6 7]}
cycles2 =
7×1 cell array
{[ 1 2 4]}
{[ 1 2 5]}
{[ 2 3 4]}
{[ 2 3 6]}
{[2 3 7 6]}
{[2 4 7 6]}
{[ 2 5 6]}
Questions:
I know cyclebasis can vary with spanning tree/edge ordering. What’s the recommended way in MATLAB to obtain “minimal loop units” that do not depend on node labeling or edge input order? For example, in the above case, each cycle is a 3-node triangle, and there should be seven such cycles. I have two undirected graphs that represent the same connectivity (isomorphic up to node relabeling). When I call cyclebasis on each, I get different sets of cycles. I understand a cycle basis can depend on the spanning tree/edge order, but I want a labeling-invariant notion of “minimal loop units.”
Code
clc; clear; close all
node = [
2 7
2 3
3 4
4 5
5 6
6 1
1 4
1 5
3 6
1 3
5 7
6 7
2 6
5 8];
G = graph(node(:,1), node(:,2), []);
cycles = cyclebasis(G)
figure(1); plot(G,’Layout’,’force’);
%%
node2 = [
1 2
2 3
3 4
4 1
1 5
5 6
2 4
6 7
3 6
2 5
3 7
4 7
2 6
6 8];
G2 = graph(node2(:,1), node2(:,2), []);
cycles2 = cyclebasis(G2)
figure(2); plot(G2,’Layout’,’force’);
Result:
cycles =
7×1 cell array
{[1 3 6 5]}
{[ 1 4 5]}
{[ 1 5 6]}
{[ 2 3 6]}
{[2 6 5 7]}
{[3 4 5 6]}
{[ 5 6 7]}
cycles2 =
7×1 cell array
{[ 1 2 4]}
{[ 1 2 5]}
{[ 2 3 4]}
{[ 2 3 6]}
{[2 3 7 6]}
{[2 4 7 6]}
{[ 2 5 6]}
Questions:
I know cyclebasis can vary with spanning tree/edge ordering. What’s the recommended way in MATLAB to obtain “minimal loop units” that do not depend on node labeling or edge input order? For example, in the above case, each cycle is a 3-node triangle, and there should be seven such cycles. graph, nodes, isomorphic, graph theory MATLAB Answers — New Questions
openfig visibility when saved figure has a callback
I used the method described here to save figures with a callback that would change their visibility to ‘on’ when opened.
fig = figure(‘Visible’,’off’);
set(fig, ‘CreateFcn’, ‘set(gcbo,”Visible”,”on”)’);
plot([1:10]);
savefig(fig,"C:temptest.fig")
close all
openfig("C:temptest.fig",’invisible’)
Behavior of sample code: figure opens and is visible
Desired Behavior: figure opens and is invisible.
Is this possible? Thank you.I used the method described here to save figures with a callback that would change their visibility to ‘on’ when opened.
fig = figure(‘Visible’,’off’);
set(fig, ‘CreateFcn’, ‘set(gcbo,”Visible”,”on”)’);
plot([1:10]);
savefig(fig,"C:temptest.fig")
close all
openfig("C:temptest.fig",’invisible’)
Behavior of sample code: figure opens and is visible
Desired Behavior: figure opens and is invisible.
Is this possible? Thank you. I used the method described here to save figures with a callback that would change their visibility to ‘on’ when opened.
fig = figure(‘Visible’,’off’);
set(fig, ‘CreateFcn’, ‘set(gcbo,”Visible”,”on”)’);
plot([1:10]);
savefig(fig,"C:temptest.fig")
close all
openfig("C:temptest.fig",’invisible’)
Behavior of sample code: figure opens and is visible
Desired Behavior: figure opens and is invisible.
Is this possible? Thank you. figure visibility MATLAB Answers — New Questions
How to avoid trimming of string cells got by readtable method?
Hello, everyone,
I am working with spreadsheet tables, which I import by readtable method. I have several numeric columns, but my crucial point is the column with strings. The readtable function trim every string (removes leading and trailing whitespace). However, I need to avoid this trimming and leave the strings as they are. I tried to look into documentation, but found only the trimming related to tables originating from text files.
My current code related to this looks following:
mytable=readtable(filename,’Sheet’,sheetname,’NumHeaderLines’,0)
Do you have any suggestions?Hello, everyone,
I am working with spreadsheet tables, which I import by readtable method. I have several numeric columns, but my crucial point is the column with strings. The readtable function trim every string (removes leading and trailing whitespace). However, I need to avoid this trimming and leave the strings as they are. I tried to look into documentation, but found only the trimming related to tables originating from text files.
My current code related to this looks following:
mytable=readtable(filename,’Sheet’,sheetname,’NumHeaderLines’,0)
Do you have any suggestions? Hello, everyone,
I am working with spreadsheet tables, which I import by readtable method. I have several numeric columns, but my crucial point is the column with strings. The readtable function trim every string (removes leading and trailing whitespace). However, I need to avoid this trimming and leave the strings as they are. I tried to look into documentation, but found only the trimming related to tables originating from text files.
My current code related to this looks following:
mytable=readtable(filename,’Sheet’,sheetname,’NumHeaderLines’,0)
Do you have any suggestions? readtable, strtrim MATLAB Answers — New Questions









