Tag Archives: matlab
PIL Simulation Warning: “Top model does not contain a referenced model” – Is My Simulation Valid?
Hello,
I am performing a Processor-in-the-Loop (PIL) simulation on a control subsystem of a fuel-cell model using Simulink/Simscape and an STM32F429 target with Embedded Coder.
I used the option "Create SIL/PIL block" for the subsystem, followed by C/C++ Code > Build This Subsystem, and then added the generated block to my model for testing(fuel-cell model).
When I run the simulation, I get the following warning:
"Top model does not contain a referenced model. ‘Simulation’ and ‘SIL/PIL Simulation’ will behave in the same way. Change ‘system under test’ or add a model block to the top model."
At the same time, the simulation output curves for normal simulation and PIL are identical (confondues), which is expected, but this warning makes me unsure.
My questions:
Does this warning indicate that the PIL simulation is not actually running on the target hardware?
Since I’m testing only a control subsystem using a PIL block, and not the entire model, is it safe to ignore this warning?
Do I need to replace the subsystem with a referenced model (Model block) to properly use PIL at the top level?
Thank you in advance for your help!Hello,
I am performing a Processor-in-the-Loop (PIL) simulation on a control subsystem of a fuel-cell model using Simulink/Simscape and an STM32F429 target with Embedded Coder.
I used the option "Create SIL/PIL block" for the subsystem, followed by C/C++ Code > Build This Subsystem, and then added the generated block to my model for testing(fuel-cell model).
When I run the simulation, I get the following warning:
"Top model does not contain a referenced model. ‘Simulation’ and ‘SIL/PIL Simulation’ will behave in the same way. Change ‘system under test’ or add a model block to the top model."
At the same time, the simulation output curves for normal simulation and PIL are identical (confondues), which is expected, but this warning makes me unsure.
My questions:
Does this warning indicate that the PIL simulation is not actually running on the target hardware?
Since I’m testing only a control subsystem using a PIL block, and not the entire model, is it safe to ignore this warning?
Do I need to replace the subsystem with a referenced model (Model block) to properly use PIL at the top level?
Thank you in advance for your help! Hello,
I am performing a Processor-in-the-Loop (PIL) simulation on a control subsystem of a fuel-cell model using Simulink/Simscape and an STM32F429 target with Embedded Coder.
I used the option "Create SIL/PIL block" for the subsystem, followed by C/C++ Code > Build This Subsystem, and then added the generated block to my model for testing(fuel-cell model).
When I run the simulation, I get the following warning:
"Top model does not contain a referenced model. ‘Simulation’ and ‘SIL/PIL Simulation’ will behave in the same way. Change ‘system under test’ or add a model block to the top model."
At the same time, the simulation output curves for normal simulation and PIL are identical (confondues), which is expected, but this warning makes me unsure.
My questions:
Does this warning indicate that the PIL simulation is not actually running on the target hardware?
Since I’m testing only a control subsystem using a PIL block, and not the entire model, is it safe to ignore this warning?
Do I need to replace the subsystem with a referenced model (Model block) to properly use PIL at the top level?
Thank you in advance for your help! pil MATLAB Answers — New Questions
How to get a smooth scalar field on regular grids from irregularly distributed sample data?
I have irregularly distributed sample data (Rs, Zs, phi00), its contourf plot looks smooth like:
I use:
phi=griddata(Rs,Zs,phi00,Rgrid,Zgrid,’cubic’);
to get the data on regular grids. There are some zigzags on the contourf plot from regular grids like:
Since we can get a smooth contourf plot from the irregular sample data, I believe that there must a simple way to get the smooth data on regular grids. How can I get it?
The sample data points and the contourf plot and the scatteredinterpolant figures are:I have irregularly distributed sample data (Rs, Zs, phi00), its contourf plot looks smooth like:
I use:
phi=griddata(Rs,Zs,phi00,Rgrid,Zgrid,’cubic’);
to get the data on regular grids. There are some zigzags on the contourf plot from regular grids like:
Since we can get a smooth contourf plot from the irregular sample data, I believe that there must a simple way to get the smooth data on regular grids. How can I get it?
The sample data points and the contourf plot and the scatteredinterpolant figures are: I have irregularly distributed sample data (Rs, Zs, phi00), its contourf plot looks smooth like:
I use:
phi=griddata(Rs,Zs,phi00,Rgrid,Zgrid,’cubic’);
to get the data on regular grids. There are some zigzags on the contourf plot from regular grids like:
Since we can get a smooth contourf plot from the irregular sample data, I believe that there must a simple way to get the smooth data on regular grids. How can I get it?
The sample data points and the contourf plot and the scatteredinterpolant figures are: interpolation MATLAB Answers — New Questions
Frequency response estimation error
error:In "frestimate(modelname,op,io,in)", it is required for each of the linearization input I/O points that the sample time of the Simulink signal where it is located is one of the following:
1. It is either continuous or fixed in minor time step.
2. Its sample rate is equal to the sample rate of the input signal "in".
The linearization I/O io(1) does not satisfy this requirement. Consider either changing the sample time of Simulink signal where io(1) is located to continuous sample time or changing the sample time of input signal "in".
However, my sampling time is already set to the same, why do I still get this error?error:In "frestimate(modelname,op,io,in)", it is required for each of the linearization input I/O points that the sample time of the Simulink signal where it is located is one of the following:
1. It is either continuous or fixed in minor time step.
2. Its sample rate is equal to the sample rate of the input signal "in".
The linearization I/O io(1) does not satisfy this requirement. Consider either changing the sample time of Simulink signal where io(1) is located to continuous sample time or changing the sample time of input signal "in".
However, my sampling time is already set to the same, why do I still get this error? error:In "frestimate(modelname,op,io,in)", it is required for each of the linearization input I/O points that the sample time of the Simulink signal where it is located is one of the following:
1. It is either continuous or fixed in minor time step.
2. Its sample rate is equal to the sample rate of the input signal "in".
The linearization I/O io(1) does not satisfy this requirement. Consider either changing the sample time of Simulink signal where io(1) is located to continuous sample time or changing the sample time of input signal "in".
However, my sampling time is already set to the same, why do I still get this error? pid control, model linearizer, simulink control design MATLAB Answers — New Questions
What is the fastest way to solve small linear programs inside a loop?
Hi,
I’m running linprog inside a large time loop to solve small (m,n <=3) linear programs but it is my code’s bottle neck. I found that using Simplex ("Large scale off) instead of interior point in the options makes it a little faster. Is there a faster way to do this? matrix "A" is always small and dense (m,n<=3). I tried TOMLAB’s MINOS and LPOPT and QPOPT but still linprog is faster. I don’t know maybe i’m not using TOMLAB correctly or that they’re just better for large problem sizes.
Is there an easy way to just code a faster LP solver for small problems. For my current problem linprog is taking ~.0012 sec for a single iteration to solve 2*2 problems. I have it inside a nested loop, below is a pseudo code:
for t =1:nt
for n = 1:N
linprog
end
end
So it would be much better to have it to be as fast as say ~0.0005 sec/iteration. I want to do this before attempting to make the inner loop parallel. The outer loop cannot be made parallel because of dependencies (time loop).
I would highly appreciate any help guys because my simulations need to be faster than real-time.
Thanks,
EyasHi,
I’m running linprog inside a large time loop to solve small (m,n <=3) linear programs but it is my code’s bottle neck. I found that using Simplex ("Large scale off) instead of interior point in the options makes it a little faster. Is there a faster way to do this? matrix "A" is always small and dense (m,n<=3). I tried TOMLAB’s MINOS and LPOPT and QPOPT but still linprog is faster. I don’t know maybe i’m not using TOMLAB correctly or that they’re just better for large problem sizes.
Is there an easy way to just code a faster LP solver for small problems. For my current problem linprog is taking ~.0012 sec for a single iteration to solve 2*2 problems. I have it inside a nested loop, below is a pseudo code:
for t =1:nt
for n = 1:N
linprog
end
end
So it would be much better to have it to be as fast as say ~0.0005 sec/iteration. I want to do this before attempting to make the inner loop parallel. The outer loop cannot be made parallel because of dependencies (time loop).
I would highly appreciate any help guys because my simulations need to be faster than real-time.
Thanks,
Eyas Hi,
I’m running linprog inside a large time loop to solve small (m,n <=3) linear programs but it is my code’s bottle neck. I found that using Simplex ("Large scale off) instead of interior point in the options makes it a little faster. Is there a faster way to do this? matrix "A" is always small and dense (m,n<=3). I tried TOMLAB’s MINOS and LPOPT and QPOPT but still linprog is faster. I don’t know maybe i’m not using TOMLAB correctly or that they’re just better for large problem sizes.
Is there an easy way to just code a faster LP solver for small problems. For my current problem linprog is taking ~.0012 sec for a single iteration to solve 2*2 problems. I have it inside a nested loop, below is a pseudo code:
for t =1:nt
for n = 1:N
linprog
end
end
So it would be much better to have it to be as fast as say ~0.0005 sec/iteration. I want to do this before attempting to make the inner loop parallel. The outer loop cannot be made parallel because of dependencies (time loop).
I would highly appreciate any help guys because my simulations need to be faster than real-time.
Thanks,
Eyas linprog, optimization, loops, speed, linear program, linear programming, nested loops, real time, simulation, tomlab, optimization toolbox, simplex, mathematics, parallel computing, mex MATLAB Answers — New Questions
How can I download the 30 Day Trial Version?
Hello all,
i have problems with my Account. I can not download the 30 Day Trial Version of MATLAB. Can anyone help me please?
With best RegardsHello all,
i have problems with my Account. I can not download the 30 Day Trial Version of MATLAB. Can anyone help me please?
With best Regards Hello all,
i have problems with my Account. I can not download the 30 Day Trial Version of MATLAB. Can anyone help me please?
With best Regards account, trial version MATLAB Answers — New Questions
No more m-file app packaging…
Hi, is it correct that GUIs built programatically (as an m file using uicontrol) can no longer be converted to a mlappinstall file in 2025a? It seems like my GUI (PIVlab) can now only be shared on file exchange as a "pure toolbox" that will be installed in a completely "random" folder (/…/…/…/AppData/Roaming/…/…/…/…/…). None of my users (including me) will intuitively know how to start the GUI. In older releases, an App could be added to the "App badge", making it very easy for new Matlab users to start the GUI. But there doesn’t seem to be a clean way to convert m-files to mlappisntall anymore. Previously an "App project" could be used together with the matlab.apputil.package could be used. Now Matlab tells me that "To package an app, create a MATLAB toolbox. "
I did that, but I cannot add an .m file as App.Hi, is it correct that GUIs built programatically (as an m file using uicontrol) can no longer be converted to a mlappinstall file in 2025a? It seems like my GUI (PIVlab) can now only be shared on file exchange as a "pure toolbox" that will be installed in a completely "random" folder (/…/…/…/AppData/Roaming/…/…/…/…/…). None of my users (including me) will intuitively know how to start the GUI. In older releases, an App could be added to the "App badge", making it very easy for new Matlab users to start the GUI. But there doesn’t seem to be a clean way to convert m-files to mlappisntall anymore. Previously an "App project" could be used together with the matlab.apputil.package could be used. Now Matlab tells me that "To package an app, create a MATLAB toolbox. "
I did that, but I cannot add an .m file as App. Hi, is it correct that GUIs built programatically (as an m file using uicontrol) can no longer be converted to a mlappinstall file in 2025a? It seems like my GUI (PIVlab) can now only be shared on file exchange as a "pure toolbox" that will be installed in a completely "random" folder (/…/…/…/AppData/Roaming/…/…/…/…/…). None of my users (including me) will intuitively know how to start the GUI. In older releases, an App could be added to the "App badge", making it very easy for new Matlab users to start the GUI. But there doesn’t seem to be a clean way to convert m-files to mlappisntall anymore. Previously an "App project" could be used together with the matlab.apputil.package could be used. Now Matlab tells me that "To package an app, create a MATLAB toolbox. "
I did that, but I cannot add an .m file as App. mlappinstall, app, toolbox, apputil MATLAB Answers — New Questions
Cannot find SoCData and rteEvent datatypes characteristics
Dear all,
I was trying to figure out the following about SoCData datatype:
1) What are its dimensions?
2) Is this real or complex signal?
Could you, please, help me to find information about this? Same qustion concerning rteEvent datatype. These datatypes are output datatypes or AXI4-Stream to Software block. I also had a feeling that these might be messages, not signals. Is this correct or not?Dear all,
I was trying to figure out the following about SoCData datatype:
1) What are its dimensions?
2) Is this real or complex signal?
Could you, please, help me to find information about this? Same qustion concerning rteEvent datatype. These datatypes are output datatypes or AXI4-Stream to Software block. I also had a feeling that these might be messages, not signals. Is this correct or not? Dear all,
I was trying to figure out the following about SoCData datatype:
1) What are its dimensions?
2) Is this real or complex signal?
Could you, please, help me to find information about this? Same qustion concerning rteEvent datatype. These datatypes are output datatypes or AXI4-Stream to Software block. I also had a feeling that these might be messages, not signals. Is this correct or not? datatype, soc blockset, socdata, dimension, signal attributes MATLAB Answers — New Questions
Help to understand RF Data Converter clocking
Dear all,
I am starting to use SoC Blockset add-on and now figuring out how RF Data Converter block works.
For example I set the following parameters in RF Data Converter:
(Sample rate 1024 MSPS, Interpolation/Decimation 1, Samples per clock cycle 4 –> Stream Clock Frequency 256MHz)
The FPGA sampling time is also set to 7.1825e-9 to correspond to Stream Clock Frequency of 256MHz.
Then, in the timing manager we can see, that the RF Data Converter transmits (updates the output dacTxChy) with Stream Clock Frequency of 256MHz.
Now we can set Interpolation/Decimation to 2 (This changes Stream Clock Frequency to 128MHz. The FPGA sampling time is unchanged.
We can now see, that RF Data Converter updates the output dacTxChy with Stream Clock Frequency of 128MHz. This "eats" some of the FPGA samples, which is bad, so I am not sure this is how I should use this block.
The question is what Interpolation setting is done for and how to apply it? Is this ok that when I set the Interpolation parameter to the value different from 1 it seems like the actual sampling frequency just decreases without any benefits? Why not then just decrease Sample rate of RF Data Converter? Thank you!Dear all,
I am starting to use SoC Blockset add-on and now figuring out how RF Data Converter block works.
For example I set the following parameters in RF Data Converter:
(Sample rate 1024 MSPS, Interpolation/Decimation 1, Samples per clock cycle 4 –> Stream Clock Frequency 256MHz)
The FPGA sampling time is also set to 7.1825e-9 to correspond to Stream Clock Frequency of 256MHz.
Then, in the timing manager we can see, that the RF Data Converter transmits (updates the output dacTxChy) with Stream Clock Frequency of 256MHz.
Now we can set Interpolation/Decimation to 2 (This changes Stream Clock Frequency to 128MHz. The FPGA sampling time is unchanged.
We can now see, that RF Data Converter updates the output dacTxChy with Stream Clock Frequency of 128MHz. This "eats" some of the FPGA samples, which is bad, so I am not sure this is how I should use this block.
The question is what Interpolation setting is done for and how to apply it? Is this ok that when I set the Interpolation parameter to the value different from 1 it seems like the actual sampling frequency just decreases without any benefits? Why not then just decrease Sample rate of RF Data Converter? Thank you! Dear all,
I am starting to use SoC Blockset add-on and now figuring out how RF Data Converter block works.
For example I set the following parameters in RF Data Converter:
(Sample rate 1024 MSPS, Interpolation/Decimation 1, Samples per clock cycle 4 –> Stream Clock Frequency 256MHz)
The FPGA sampling time is also set to 7.1825e-9 to correspond to Stream Clock Frequency of 256MHz.
Then, in the timing manager we can see, that the RF Data Converter transmits (updates the output dacTxChy) with Stream Clock Frequency of 256MHz.
Now we can set Interpolation/Decimation to 2 (This changes Stream Clock Frequency to 128MHz. The FPGA sampling time is unchanged.
We can now see, that RF Data Converter updates the output dacTxChy with Stream Clock Frequency of 128MHz. This "eats" some of the FPGA samples, which is bad, so I am not sure this is how I should use this block.
The question is what Interpolation setting is done for and how to apply it? Is this ok that when I set the Interpolation parameter to the value different from 1 it seems like the actual sampling frequency just decreases without any benefits? Why not then just decrease Sample rate of RF Data Converter? Thank you! soc blockset, rf data converter, sampling frequency, interpolation, clocking, fpga, dac, adc MATLAB Answers — New Questions
AXI4-Stream to Software clock frequency does not match FPGA clock frequency
Dear all,
I am using SoC Blockset add-on and checking out the example "Transmit and Receive Tone Using RFSoC Device" (https://www.mathworks.com/help/soc/ug/transmit-and-receive-tone-using-RFSoC-device-simulate.html). The FPGA Clock frequency (SampleTime) is set to 128MHz, but the AXI4-Stream to Software clock is set to 200MHz. How are then all the samples written to memory if the memory clock is slower than the sample production frequency?
How does in general AXI4-Stream to Software block work? The following qustions are not answered in the documentation (https://www.mathworks.com/help/soc/ref/axi4streamtosoftware.html):
1) Does one buffer contatin multiple bursts? If yes, how many?
2) With what rate is burst written to buffer?
3) With what rate are samples saved in burst (to be written to buffer later)?
4) Are samples written to FIFO with the same rate as in the previous question?
Thank you!Dear all,
I am using SoC Blockset add-on and checking out the example "Transmit and Receive Tone Using RFSoC Device" (https://www.mathworks.com/help/soc/ug/transmit-and-receive-tone-using-RFSoC-device-simulate.html). The FPGA Clock frequency (SampleTime) is set to 128MHz, but the AXI4-Stream to Software clock is set to 200MHz. How are then all the samples written to memory if the memory clock is slower than the sample production frequency?
How does in general AXI4-Stream to Software block work? The following qustions are not answered in the documentation (https://www.mathworks.com/help/soc/ref/axi4streamtosoftware.html):
1) Does one buffer contatin multiple bursts? If yes, how many?
2) With what rate is burst written to buffer?
3) With what rate are samples saved in burst (to be written to buffer later)?
4) Are samples written to FIFO with the same rate as in the previous question?
Thank you! Dear all,
I am using SoC Blockset add-on and checking out the example "Transmit and Receive Tone Using RFSoC Device" (https://www.mathworks.com/help/soc/ug/transmit-and-receive-tone-using-RFSoC-device-simulate.html). The FPGA Clock frequency (SampleTime) is set to 128MHz, but the AXI4-Stream to Software clock is set to 200MHz. How are then all the samples written to memory if the memory clock is slower than the sample production frequency?
How does in general AXI4-Stream to Software block work? The following qustions are not answered in the documentation (https://www.mathworks.com/help/soc/ref/axi4streamtosoftware.html):
1) Does one buffer contatin multiple bursts? If yes, how many?
2) With what rate is burst written to buffer?
3) With what rate are samples saved in burst (to be written to buffer later)?
4) Are samples written to FIFO with the same rate as in the previous question?
Thank you! clock, soc blockset, axi4-stream to software, axi4, fpga, sampling, fifo, buffer, burst, clock frequency MATLAB Answers — New Questions
Need a tangent line in my plot like the example provided but I cannot seem to do it
I am trying to make a tangent or line of best fit t this data but only from the second half of the plot on should be focused on. Below is an example from the professor
Need smething like this…
which translates to something like this…
But for some reason I keep getting this…
By using this code…
%% Calculation Problem 2
%Given Data Problems 1-4
dd = load(‘NEWPROB6.txt’) %Data loading for airfoil
alpha = dd(:,1); %Angle of attacks (Degreed)
CL = dd(:,2); %Lift coefficient
CD = dd(:,3); %Drag coefficient
Rh = 0.75; %Turbine hub radius (m)
Rt = 15; %Turbine blade tip radius (m)
Rht = linspace(Rh,Rt,10); %r/R radius hub to tip (m)
Rr = Rht/Rt;
B = 3; %Number of blades on the turbine
TSR = 8; %Tips-speed ratio
%Calculation Problem 1
CLD = CL./CD %Lift-to-Drag Ratio
TCL = 1.0280 %Lift coefficient associated with maximum lift-to-drag ratio
Talpha = 6 %Target angle of attack (degrees)
%Calculation Problem 2
Phi = atand(2./(3*TSR*(Rr))) %Local inflow angle (degrees)
CrR = Rt*(8*pi*sind(Phi))./(3*B*TCL*TSR); %chord distribution
Beta = Phi-Talpha
subplot(2,1,1)
plot(Rht,CrR, ‘b.-‘, ‘LineWidth’,2, ‘MarkerSize’, 20)
halfpoints = round(numel(CrR)/2)
xlabel(‘r/R’)
ylabel(‘Chord Distribution (m)’)
grid on
hold on
% Assume x and y are your data vectors
xline(Rht(halfpoints), ‘Color’, ‘r’)
% Get halfway index
RhtHalf = Rht(halfpoints : end)
CrRHalf = CrR(halfpoints : end)
coefficients = polyfit(RhtHalf, CrRHalf, 1)
RhtFitted = linspace(5, 10, 1)
CrRFitted = polyval(coefficients, RhtFitted);
plot(RhtFitted, CrRFitted, ‘c–‘, ‘LineWidth’, 2)
grid on
legend(‘Original Data’, ‘Linear Fit (2nd Half)’);
hold off
Does anyone know how I can fix this?I am trying to make a tangent or line of best fit t this data but only from the second half of the plot on should be focused on. Below is an example from the professor
Need smething like this…
which translates to something like this…
But for some reason I keep getting this…
By using this code…
%% Calculation Problem 2
%Given Data Problems 1-4
dd = load(‘NEWPROB6.txt’) %Data loading for airfoil
alpha = dd(:,1); %Angle of attacks (Degreed)
CL = dd(:,2); %Lift coefficient
CD = dd(:,3); %Drag coefficient
Rh = 0.75; %Turbine hub radius (m)
Rt = 15; %Turbine blade tip radius (m)
Rht = linspace(Rh,Rt,10); %r/R radius hub to tip (m)
Rr = Rht/Rt;
B = 3; %Number of blades on the turbine
TSR = 8; %Tips-speed ratio
%Calculation Problem 1
CLD = CL./CD %Lift-to-Drag Ratio
TCL = 1.0280 %Lift coefficient associated with maximum lift-to-drag ratio
Talpha = 6 %Target angle of attack (degrees)
%Calculation Problem 2
Phi = atand(2./(3*TSR*(Rr))) %Local inflow angle (degrees)
CrR = Rt*(8*pi*sind(Phi))./(3*B*TCL*TSR); %chord distribution
Beta = Phi-Talpha
subplot(2,1,1)
plot(Rht,CrR, ‘b.-‘, ‘LineWidth’,2, ‘MarkerSize’, 20)
halfpoints = round(numel(CrR)/2)
xlabel(‘r/R’)
ylabel(‘Chord Distribution (m)’)
grid on
hold on
% Assume x and y are your data vectors
xline(Rht(halfpoints), ‘Color’, ‘r’)
% Get halfway index
RhtHalf = Rht(halfpoints : end)
CrRHalf = CrR(halfpoints : end)
coefficients = polyfit(RhtHalf, CrRHalf, 1)
RhtFitted = linspace(5, 10, 1)
CrRFitted = polyval(coefficients, RhtFitted);
plot(RhtFitted, CrRFitted, ‘c–‘, ‘LineWidth’, 2)
grid on
legend(‘Original Data’, ‘Linear Fit (2nd Half)’);
hold off
Does anyone know how I can fix this? I am trying to make a tangent or line of best fit t this data but only from the second half of the plot on should be focused on. Below is an example from the professor
Need smething like this…
which translates to something like this…
But for some reason I keep getting this…
By using this code…
%% Calculation Problem 2
%Given Data Problems 1-4
dd = load(‘NEWPROB6.txt’) %Data loading for airfoil
alpha = dd(:,1); %Angle of attacks (Degreed)
CL = dd(:,2); %Lift coefficient
CD = dd(:,3); %Drag coefficient
Rh = 0.75; %Turbine hub radius (m)
Rt = 15; %Turbine blade tip radius (m)
Rht = linspace(Rh,Rt,10); %r/R radius hub to tip (m)
Rr = Rht/Rt;
B = 3; %Number of blades on the turbine
TSR = 8; %Tips-speed ratio
%Calculation Problem 1
CLD = CL./CD %Lift-to-Drag Ratio
TCL = 1.0280 %Lift coefficient associated with maximum lift-to-drag ratio
Talpha = 6 %Target angle of attack (degrees)
%Calculation Problem 2
Phi = atand(2./(3*TSR*(Rr))) %Local inflow angle (degrees)
CrR = Rt*(8*pi*sind(Phi))./(3*B*TCL*TSR); %chord distribution
Beta = Phi-Talpha
subplot(2,1,1)
plot(Rht,CrR, ‘b.-‘, ‘LineWidth’,2, ‘MarkerSize’, 20)
halfpoints = round(numel(CrR)/2)
xlabel(‘r/R’)
ylabel(‘Chord Distribution (m)’)
grid on
hold on
% Assume x and y are your data vectors
xline(Rht(halfpoints), ‘Color’, ‘r’)
% Get halfway index
RhtHalf = Rht(halfpoints : end)
CrRHalf = CrR(halfpoints : end)
coefficients = polyfit(RhtHalf, CrRHalf, 1)
RhtFitted = linspace(5, 10, 1)
CrRFitted = polyval(coefficients, RhtFitted);
plot(RhtFitted, CrRFitted, ‘c–‘, ‘LineWidth’, 2)
grid on
legend(‘Original Data’, ‘Linear Fit (2nd Half)’);
hold off
Does anyone know how I can fix this? tangent line, line of best fit, regression line, plotting, matlab MATLAB Answers — New Questions
How can I simulate a pv/wind/battery hybrid microgrid for a rural area in kapiri with errors?
Those are my values for the area I’ve chosen and simulated block diagrams that I tried to simulate but the waveforms are not being produced. Please help me spot the mistakes I made and help with simulations that would with my area specifications.Those are my values for the area I’ve chosen and simulated block diagrams that I tried to simulate but the waveforms are not being produced. Please help me spot the mistakes I made and help with simulations that would with my area specifications. Those are my values for the area I’ve chosen and simulated block diagrams that I tried to simulate but the waveforms are not being produced. Please help me spot the mistakes I made and help with simulations that would with my area specifications. final year project MATLAB Answers — New Questions
How do I dock figures next to the editor by default ?
set(0,’DefaultFigureWindowStyle’,’docked’) does not work. It still opens the figure in a new windows an I have to right click and click on "Dock figures". Alternatively I can press CTRL+Shift+D but I dont want to do that. Typing get(0,’DefaultFigureWindowStyle’) gives me "docked" as an answer so the command is working appearently.
How can I make it so the figure appears next to the editor by default without me pressing CTRL+Shift+D everytime ?set(0,’DefaultFigureWindowStyle’,’docked’) does not work. It still opens the figure in a new windows an I have to right click and click on "Dock figures". Alternatively I can press CTRL+Shift+D but I dont want to do that. Typing get(0,’DefaultFigureWindowStyle’) gives me "docked" as an answer so the command is working appearently.
How can I make it so the figure appears next to the editor by default without me pressing CTRL+Shift+D everytime ? set(0,’DefaultFigureWindowStyle’,’docked’) does not work. It still opens the figure in a new windows an I have to right click and click on "Dock figures". Alternatively I can press CTRL+Shift+D but I dont want to do that. Typing get(0,’DefaultFigureWindowStyle’) gives me "docked" as an answer so the command is working appearently.
How can I make it so the figure appears next to the editor by default without me pressing CTRL+Shift+D everytime ? figure, graph, matlab, gui, default MATLAB Answers — New Questions
Word Matlab Notebook and figures…
Have a script generating several figures — may be 10 or more eventually.
Need to use these in a Word document for distribution so thought the *notebook* thingie would be pretty simple–just execute the script and voila! the figures should show up (or so I thought, anyways).
Instead the script runs, I see the figures flash by, but all that’s left in the document is the last one; none of the rest are to be found anywhere.
Is this expected; if not how to cure the symptom in R2012b or if is a limitation, is there some other quick ‘n dirty way to accomplish the job?Have a script generating several figures — may be 10 or more eventually.
Need to use these in a Word document for distribution so thought the *notebook* thingie would be pretty simple–just execute the script and voila! the figures should show up (or so I thought, anyways).
Instead the script runs, I see the figures flash by, but all that’s left in the document is the last one; none of the rest are to be found anywhere.
Is this expected; if not how to cure the symptom in R2012b or if is a limitation, is there some other quick ‘n dirty way to accomplish the job? Have a script generating several figures — may be 10 or more eventually.
Need to use these in a Word document for distribution so thought the *notebook* thingie would be pretty simple–just execute the script and voila! the figures should show up (or so I thought, anyways).
Instead the script runs, I see the figures flash by, but all that’s left in the document is the last one; none of the rest are to be found anywhere.
Is this expected; if not how to cure the symptom in R2012b or if is a limitation, is there some other quick ‘n dirty way to accomplish the job? word notebook, figures MATLAB Answers — New Questions
Looking for sensor in simulink to sense distance between two vehicles
I am trying to find a sensor in the simulink library to detect distance between two vehicles. I am doing my final year project which is a fuzzy logic collision avoidance system. I am trying to model it using matlab and simulink. Can anyone point me in the right direction with respect to where i can find the sensor input in the library? Also i am looking for one to detect the rate of change in velocity of the vehicle in front of the other one.I am trying to find a sensor in the simulink library to detect distance between two vehicles. I am doing my final year project which is a fuzzy logic collision avoidance system. I am trying to model it using matlab and simulink. Can anyone point me in the right direction with respect to where i can find the sensor input in the library? Also i am looking for one to detect the rate of change in velocity of the vehicle in front of the other one. I am trying to find a sensor in the simulink library to detect distance between two vehicles. I am doing my final year project which is a fuzzy logic collision avoidance system. I am trying to model it using matlab and simulink. Can anyone point me in the right direction with respect to where i can find the sensor input in the library? Also i am looking for one to detect the rate of change in velocity of the vehicle in front of the other one. simulink, matlab MATLAB Answers — New Questions
MATLAB and C++ Automatic coupling
Hi support,
I would like to develop an automatic coupling between C++ and MATLAB .
In simple Word:
* – Import in C++ the data from a .mat file
* – Run the simulation in C++
* – Export the results back in a .mat file
Based on the above details of my case, could you advise me for a way to start with?
Please let me know if you require any further clarifications.
Thank you for your continuous support.
Yahia Alabbasi B.C.Eng (Hons)
Research Assistant- Qatar University-Department of Civil and Architectural EngineeringHi support,
I would like to develop an automatic coupling between C++ and MATLAB .
In simple Word:
* – Import in C++ the data from a .mat file
* – Run the simulation in C++
* – Export the results back in a .mat file
Based on the above details of my case, could you advise me for a way to start with?
Please let me know if you require any further clarifications.
Thank you for your continuous support.
Yahia Alabbasi B.C.Eng (Hons)
Research Assistant- Qatar University-Department of Civil and Architectural Engineering Hi support,
I would like to develop an automatic coupling between C++ and MATLAB .
In simple Word:
* – Import in C++ the data from a .mat file
* – Run the simulation in C++
* – Export the results back in a .mat file
Based on the above details of my case, could you advise me for a way to start with?
Please let me know if you require any further clarifications.
Thank you for your continuous support.
Yahia Alabbasi B.C.Eng (Hons)
Research Assistant- Qatar University-Department of Civil and Architectural Engineering c++, matlab, data import, export MATLAB Answers — New Questions
Can’t use MATLAB on fedora 42
After about 1 minute matlab crashes every time with the following error:
Unable to communicate with required MathWorks services (error 5201).
I have tried reinstalling MathWorks services as suggested elsewhere, and it dind’t change anything.After about 1 minute matlab crashes every time with the following error:
Unable to communicate with required MathWorks services (error 5201).
I have tried reinstalling MathWorks services as suggested elsewhere, and it dind’t change anything. After about 1 minute matlab crashes every time with the following error:
Unable to communicate with required MathWorks services (error 5201).
I have tried reinstalling MathWorks services as suggested elsewhere, and it dind’t change anything. linux, fedora, mathwork services MATLAB Answers — New Questions
How to Resize images stored in matlab.io.datastore.ImageDatastore to [224 224 3]
Hello I’m new in using pretrained networks in MATLAB for Object Detection and I was following a guide in Youtube which uses YOLO for detection. In this guide, it also used the resnet50 pretrained network which has an input layer that expects images of size (224x224x3).
Below is the code:
trainData1 = Data;
%%% Create resnet50 pretrained network
netWidth = 16;
layers = [
imageInputLayer([224 224 3], ‘Name’, ‘input’)
convolution2dLayer(3, netWidth, ‘Padding’,’same’, ‘Name’, ‘convInp’)
batchNormalizationLayer(‘Name’, ‘BNInp’)
reluLayer(‘Name’, ‘reluInp’)
convolutionalUnit(netWidth, 1, ‘S1U1’)
additionLayer(2, ‘Name’, ‘add11’)
reluLayer(‘Name’, ‘relu11’)
convolutionalUnit(netWidth, 1, ‘S1U2’)
additionLayer(2, ‘Name’, ‘add12’)
reluLayer(‘Name’, ‘relu12’)
convolutionalUnit(2*netWidth, 2, ‘S2U1’)
additionLayer(2, ‘Name’, ‘add21’)
reluLayer(‘Name’, ‘relu21’)
convolutionalUnit(2*netWidth , 1, ‘S2U2’)
additionLayer(2, ‘Name’, ‘add22’)
reluLayer(‘Name’, ‘relu22’)
convolutionalUnit(4*netWidth, 2, ‘S3U1’)
additionLayer(2, ‘Name’, ‘add31’)
reluLayer(‘Name’, ‘relu31’)
convolutionalUnit(4*netWidth, 1, ‘S3U2’)
additionLayer(2, ‘Name’, ‘add32’)
reluLayer(‘Name’, ‘relu32’)
averagePooling2dLayer(8, ‘Name’, ‘globalPool’)
fullyConnectedLayer(4, ‘Name’, ‘fcFinal’)
softmaxLayer(‘Name’, ‘softmax’)
classificationLayer(‘Name’, ‘classoutput’)
];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, ‘reluInp’, ‘add11/in2’);
lgraph = connectLayers(lgraph, ‘relu11’, ‘add12/in2’);
skip1 = [
convolution2dLayer(1,2*netWidth, ‘Stride’, 2, ‘Name’, ‘skipConv1’)
batchNormalizationLayer(‘Name’, ‘skipBN1’)];
lgraph = addLayers(lgraph, skip1);
lgraph = connectLayers(lgraph, ‘relu12’, ‘skipConv1’);
lgraph = connectLayers(lgraph, ‘skipBN1’, ‘add21/in2’);
lgraph = connectLayers(lgraph, ‘relu21’, ‘add22/in2’);
skip2 = [
convolution2dLayer(1, 4*netWidth, ‘Stride’,2, ‘Name’, ‘skipConv2’)
batchNormalizationLayer(‘Name’,’skipBN2′)];
lgraph = addLayers(lgraph, skip2);
lgraph = connectLayers(lgraph, ‘relu22’, ‘skipConv2’);
lgraph = connectLayers(lgraph, ‘skipBN2’, ‘add31/in2’);
%add last identity connection and plot the final layer graph
lgraph = connectLayers(lgraph, ‘relu31’, ‘add32/in2’);
%training options
options = trainingOptions("sgdm", …
‘MiniBatchSize’, 128, …
‘MaxEpochs’, 1, …
‘InitialLearnRate’,1e-4);
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
And the output error is this:
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
Error using trainNetwork
The training images are of size 3024×4032×3 but the input layer expects images of size 224×224×3.
My workspace is this:
Thank You. Hope You Can Help.Hello I’m new in using pretrained networks in MATLAB for Object Detection and I was following a guide in Youtube which uses YOLO for detection. In this guide, it also used the resnet50 pretrained network which has an input layer that expects images of size (224x224x3).
Below is the code:
trainData1 = Data;
%%% Create resnet50 pretrained network
netWidth = 16;
layers = [
imageInputLayer([224 224 3], ‘Name’, ‘input’)
convolution2dLayer(3, netWidth, ‘Padding’,’same’, ‘Name’, ‘convInp’)
batchNormalizationLayer(‘Name’, ‘BNInp’)
reluLayer(‘Name’, ‘reluInp’)
convolutionalUnit(netWidth, 1, ‘S1U1’)
additionLayer(2, ‘Name’, ‘add11’)
reluLayer(‘Name’, ‘relu11’)
convolutionalUnit(netWidth, 1, ‘S1U2’)
additionLayer(2, ‘Name’, ‘add12’)
reluLayer(‘Name’, ‘relu12’)
convolutionalUnit(2*netWidth, 2, ‘S2U1’)
additionLayer(2, ‘Name’, ‘add21’)
reluLayer(‘Name’, ‘relu21’)
convolutionalUnit(2*netWidth , 1, ‘S2U2’)
additionLayer(2, ‘Name’, ‘add22’)
reluLayer(‘Name’, ‘relu22’)
convolutionalUnit(4*netWidth, 2, ‘S3U1’)
additionLayer(2, ‘Name’, ‘add31’)
reluLayer(‘Name’, ‘relu31’)
convolutionalUnit(4*netWidth, 1, ‘S3U2’)
additionLayer(2, ‘Name’, ‘add32’)
reluLayer(‘Name’, ‘relu32’)
averagePooling2dLayer(8, ‘Name’, ‘globalPool’)
fullyConnectedLayer(4, ‘Name’, ‘fcFinal’)
softmaxLayer(‘Name’, ‘softmax’)
classificationLayer(‘Name’, ‘classoutput’)
];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, ‘reluInp’, ‘add11/in2’);
lgraph = connectLayers(lgraph, ‘relu11’, ‘add12/in2’);
skip1 = [
convolution2dLayer(1,2*netWidth, ‘Stride’, 2, ‘Name’, ‘skipConv1’)
batchNormalizationLayer(‘Name’, ‘skipBN1’)];
lgraph = addLayers(lgraph, skip1);
lgraph = connectLayers(lgraph, ‘relu12’, ‘skipConv1’);
lgraph = connectLayers(lgraph, ‘skipBN1’, ‘add21/in2’);
lgraph = connectLayers(lgraph, ‘relu21’, ‘add22/in2’);
skip2 = [
convolution2dLayer(1, 4*netWidth, ‘Stride’,2, ‘Name’, ‘skipConv2’)
batchNormalizationLayer(‘Name’,’skipBN2′)];
lgraph = addLayers(lgraph, skip2);
lgraph = connectLayers(lgraph, ‘relu22’, ‘skipConv2’);
lgraph = connectLayers(lgraph, ‘skipBN2’, ‘add31/in2’);
%add last identity connection and plot the final layer graph
lgraph = connectLayers(lgraph, ‘relu31’, ‘add32/in2’);
%training options
options = trainingOptions("sgdm", …
‘MiniBatchSize’, 128, …
‘MaxEpochs’, 1, …
‘InitialLearnRate’,1e-4);
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
And the output error is this:
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
Error using trainNetwork
The training images are of size 3024×4032×3 but the input layer expects images of size 224×224×3.
My workspace is this:
Thank You. Hope You Can Help. Hello I’m new in using pretrained networks in MATLAB for Object Detection and I was following a guide in Youtube which uses YOLO for detection. In this guide, it also used the resnet50 pretrained network which has an input layer that expects images of size (224x224x3).
Below is the code:
trainData1 = Data;
%%% Create resnet50 pretrained network
netWidth = 16;
layers = [
imageInputLayer([224 224 3], ‘Name’, ‘input’)
convolution2dLayer(3, netWidth, ‘Padding’,’same’, ‘Name’, ‘convInp’)
batchNormalizationLayer(‘Name’, ‘BNInp’)
reluLayer(‘Name’, ‘reluInp’)
convolutionalUnit(netWidth, 1, ‘S1U1’)
additionLayer(2, ‘Name’, ‘add11’)
reluLayer(‘Name’, ‘relu11’)
convolutionalUnit(netWidth, 1, ‘S1U2’)
additionLayer(2, ‘Name’, ‘add12’)
reluLayer(‘Name’, ‘relu12’)
convolutionalUnit(2*netWidth, 2, ‘S2U1’)
additionLayer(2, ‘Name’, ‘add21’)
reluLayer(‘Name’, ‘relu21’)
convolutionalUnit(2*netWidth , 1, ‘S2U2’)
additionLayer(2, ‘Name’, ‘add22’)
reluLayer(‘Name’, ‘relu22’)
convolutionalUnit(4*netWidth, 2, ‘S3U1’)
additionLayer(2, ‘Name’, ‘add31’)
reluLayer(‘Name’, ‘relu31’)
convolutionalUnit(4*netWidth, 1, ‘S3U2’)
additionLayer(2, ‘Name’, ‘add32’)
reluLayer(‘Name’, ‘relu32’)
averagePooling2dLayer(8, ‘Name’, ‘globalPool’)
fullyConnectedLayer(4, ‘Name’, ‘fcFinal’)
softmaxLayer(‘Name’, ‘softmax’)
classificationLayer(‘Name’, ‘classoutput’)
];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, ‘reluInp’, ‘add11/in2’);
lgraph = connectLayers(lgraph, ‘relu11’, ‘add12/in2’);
skip1 = [
convolution2dLayer(1,2*netWidth, ‘Stride’, 2, ‘Name’, ‘skipConv1’)
batchNormalizationLayer(‘Name’, ‘skipBN1’)];
lgraph = addLayers(lgraph, skip1);
lgraph = connectLayers(lgraph, ‘relu12’, ‘skipConv1’);
lgraph = connectLayers(lgraph, ‘skipBN1’, ‘add21/in2’);
lgraph = connectLayers(lgraph, ‘relu21’, ‘add22/in2’);
skip2 = [
convolution2dLayer(1, 4*netWidth, ‘Stride’,2, ‘Name’, ‘skipConv2’)
batchNormalizationLayer(‘Name’,’skipBN2′)];
lgraph = addLayers(lgraph, skip2);
lgraph = connectLayers(lgraph, ‘relu22’, ‘skipConv2’);
lgraph = connectLayers(lgraph, ‘skipBN2’, ‘add31/in2’);
%add last identity connection and plot the final layer graph
lgraph = connectLayers(lgraph, ‘relu31’, ‘add32/in2’);
%training options
options = trainingOptions("sgdm", …
‘MiniBatchSize’, 128, …
‘MaxEpochs’, 1, …
‘InitialLearnRate’,1e-4);
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
And the output error is this:
% network training
[trainedNet1, traininfo] = trainNetwork(trainData1, lgraph, options);
Error using trainNetwork
The training images are of size 3024×4032×3 but the input layer expects images of size 224×224×3.
My workspace is this:
Thank You. Hope You Can Help. image processing, object detection, yolo, matlab, resizing, resnet50 MATLAB Answers — New Questions
How to present the content of a field in a program?
I want to present the variables and their value from a structure in a program, just for information for the users.
Let’s say:
a.a=234.5;
a.b=444;
a.s=’This is an example’;
a
if I run this code in the command window, I get the answer:
a =
struct with fields:
a: 234.5
b: 444
s: ‘This is an example’
I want to reproduce this answer and put it in a text window in my program. I could not figure out how to do that.
Thanks for any help!I want to present the variables and their value from a structure in a program, just for information for the users.
Let’s say:
a.a=234.5;
a.b=444;
a.s=’This is an example’;
a
if I run this code in the command window, I get the answer:
a =
struct with fields:
a: 234.5
b: 444
s: ‘This is an example’
I want to reproduce this answer and put it in a text window in my program. I could not figure out how to do that.
Thanks for any help! I want to present the variables and their value from a structure in a program, just for information for the users.
Let’s say:
a.a=234.5;
a.b=444;
a.s=’This is an example’;
a
if I run this code in the command window, I get the answer:
a =
struct with fields:
a: 234.5
b: 444
s: ‘This is an example’
I want to reproduce this answer and put it in a text window in my program. I could not figure out how to do that.
Thanks for any help! matlab, fields, structures MATLAB Answers — New Questions
I encountered the error ‘The MATLAB Editor requires Java.’
I encountered the error’The MATLAB Editor requires Java.’
while following the ‘Run Batch Parallel Jobs’ tutorial. I am seeking assistance with this issue.
+ Java’s version on my PC is
version -java
‘Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode’
And I have already installed the latest version of Java from Oracle.
The code I executed is shown below:
mywave.m
edit mywave
for i = 1:1024
A(i) = sin(i*2*pi/1024);
end
Untitled.m
job = batch(‘mywave’)
wait(job)
load(job)
Error message in Command window is shown below:
Error using parallel.Job/load (line 36)
Error encountered while running the batch job. The error was:
Error using edit (line 73)
The MATLAB Editor requires Java.
Error in mywave (line 1)
The same issue occurred in both (R2024a) and (R2023a).I encountered the error’The MATLAB Editor requires Java.’
while following the ‘Run Batch Parallel Jobs’ tutorial. I am seeking assistance with this issue.
+ Java’s version on my PC is
version -java
‘Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode’
And I have already installed the latest version of Java from Oracle.
The code I executed is shown below:
mywave.m
edit mywave
for i = 1:1024
A(i) = sin(i*2*pi/1024);
end
Untitled.m
job = batch(‘mywave’)
wait(job)
load(job)
Error message in Command window is shown below:
Error using parallel.Job/load (line 36)
Error encountered while running the batch job. The error was:
Error using edit (line 73)
The MATLAB Editor requires Java.
Error in mywave (line 1)
The same issue occurred in both (R2024a) and (R2023a). I encountered the error’The MATLAB Editor requires Java.’
while following the ‘Run Batch Parallel Jobs’ tutorial. I am seeking assistance with this issue.
+ Java’s version on my PC is
version -java
‘Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode’
And I have already installed the latest version of Java from Oracle.
The code I executed is shown below:
mywave.m
edit mywave
for i = 1:1024
A(i) = sin(i*2*pi/1024);
end
Untitled.m
job = batch(‘mywave’)
wait(job)
load(job)
Error message in Command window is shown below:
Error using parallel.Job/load (line 36)
Error encountered while running the batch job. The error was:
Error using edit (line 73)
The MATLAB Editor requires Java.
Error in mywave (line 1)
The same issue occurred in both (R2024a) and (R2023a). java MATLAB Answers — New Questions
How to do setup data queue handling between app designer and parallel thread?
Hello community
I want to use the Parallel Pool Box in App Designer to run a parallel thread and pass information between the two entitiies.
Imagine the following use case: You want to start, pause and abort i.e. a sequence of measurements from the GUI
In case the start is activated the start button changes to pause button and starts in parallel the measurement sequence.
In case the executions is paused, the current step of the sequence is allowed to be finished.
In case of abort the measurement shall be stopped immediatly and the instruments gracefully turned off.
I tried to represent this in a workflow (shown at end of post- file follows as soon as upload works again). And did setup a simplified .mlapp first trying to start a parallel thread queueing information and the main code fetching that information and diplaying it in a text area. But in that form I cannot save it as .mlapp file. From what I’ve read so far in the forum (see list below) it seems to be an issue of handing over the app object to the parallel process. But I don’t understand what I am doing wrong and thus think I missed an important part of the data queue handling. I would be glad for any hint/information/support to fix this issue and learn from that mistake.
Further information I checked prior to set up .mlapp:
https://ch.mathworks.com/matlabcentral/answers/867683-how-to-use-threads-in-matlab-app-designer/
https://ch.mathworks.com/matlabcentral/answers/1413247-threading-in-matlab-gui-callbacks
https://ch.mathworks.com/matlabcentral/answers/2164600-integrating-parallel-computing-with-app-designer-for-real-time-ui-updates
– https://www.mathworks.com/matlabcentral/answers/366576-will-there-be-a-support-of-the-parallel-toolbox-in-matlab-app-designer#comment_720548
https://ch.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.html
https://ch.mathworks.com/help/parallel-computing/parpool.html
https://ch.mathworks.com/help/parallel-computing/parallel.pool.pollabledataqueue.html
https://ch.mathworks.com/help/parallel-computing/receive-communications-on-workers.html
https://in.mathworks.com/matlabcentral/answers/1726505-proper-use-of-dataqueue-and-pollabledataqueue-inside-of-app-designer-class
Example code which can not be saved as .mlapp
classdef ExampleWorkflowAbortAsyn < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Abort2Button matlab.ui.control.StateButton
TextArea matlab.ui.control.TextArea
AbortButton matlab.ui.control.Button
StartButton matlab.ui.control.Button
end
properties (Access = public)
TCindex % Description
isPassed = false;
asycnWorker
dataQueue
clientQueue
helperClientQueue
end
methods (Static)
function receiveDataOnClient(data)
disp(data);
drawnow limitrate;
end
end
methods (Access = public)
function testExecutionMaster(app)
while strcmp(app.StartButton.Text, ‘Pause’)
app.isPassed = false;
updateUILog(app,sprintf(‘TC %i’, app.TCindex));
app.TCindex = app.TCindex + 1;
updateUILog(app,sprintf(‘tPrepare measurement…’));
pause(1)
updateUILog(app,sprintf(‘tExecute measurement…’));
pause(1)
updateUILog(app,sprintf(‘tAnalyze Measurement…’));
pause(1)
updateUILog(app,sprintf(‘t Test passed :)’));
app.isPassed = true;
end
end
function abortMeasurementAction(app)
% nice to have: pop up with abort error and instructions
updateUILog(app,’User triggerd abort starts’);
updateUILog(app,sprintf(‘tAll devices off’));
end
function updateUILog(app,message)
textArray = app.TextArea.Value;
textArray{end+1} = message;
app.TextArea.Value = textArray;
scroll(app.TextArea, ‘bottom’)
% createDiaryEntry(app, message)
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function EnterTestState(app, event)
switch app.StartButton.Text
case ‘Start’
app.StartButton.Text = ‘Pause’;
app.TCindex = 1;
asycnWorker = parpool(‘Threads’,1);
clientQueue = parallel.pool.DataQueue;
afterEach(clientQueue,@(data) app.receiveDataOnClient(data));
helperClientQueue = parallel.pool.PollableDataQueue;
temp = app.StartButton.Text;
wkrF = parallel.FevalFuture;
wkrF = parfeval(@testExecutionWorker,0,temp);
wkrQueue = poll(helperClientQueue,inf);
send(wkrQueue.Queue,"Start generating data");
case ‘Pause’
app.StartButton.Text = ‘Resume’;
updateUILog(app,’Test execution enters pause state’)
while ~app.isPassed
pause(0.2)
end
updateUILog(app,sprintf(‘Test execution paused at %i’, app.TCindex));
case ‘Resume’
app.StartButton.Text = ‘Pause’;
updateUILog(app,’Resume test execution’);
testExecutionMaster(app)
end
updateUILog(app,"End of EnterTestStateFunction")
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create StartButton
app.StartButton = uibutton(app.UIFigure, ‘push’);
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @EnterTestState, true);
app.StartButton.Position = [422 321 138 45];
app.StartButton.Text = ‘Start’;
% Create AbortButton
app.AbortButton = uibutton(app.UIFigure, ‘push’);
app.AbortButton.Position = [422 249 138 41];
app.AbortButton.Text = ‘Abort’;
% Create TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.Editable = ‘off’;
app.TextArea.Position = [60 28 475 168];
% Create Abort2Button
app.Abort2Button = uibutton(app.UIFigure, ‘state’);
app.Abort2Button.Text = ‘Abort2’;
app.Abort2Button.Position = [129 289 186 54];
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ExampleWorkflowAbortAsyn
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
endHello community
I want to use the Parallel Pool Box in App Designer to run a parallel thread and pass information between the two entitiies.
Imagine the following use case: You want to start, pause and abort i.e. a sequence of measurements from the GUI
In case the start is activated the start button changes to pause button and starts in parallel the measurement sequence.
In case the executions is paused, the current step of the sequence is allowed to be finished.
In case of abort the measurement shall be stopped immediatly and the instruments gracefully turned off.
I tried to represent this in a workflow (shown at end of post- file follows as soon as upload works again). And did setup a simplified .mlapp first trying to start a parallel thread queueing information and the main code fetching that information and diplaying it in a text area. But in that form I cannot save it as .mlapp file. From what I’ve read so far in the forum (see list below) it seems to be an issue of handing over the app object to the parallel process. But I don’t understand what I am doing wrong and thus think I missed an important part of the data queue handling. I would be glad for any hint/information/support to fix this issue and learn from that mistake.
Further information I checked prior to set up .mlapp:
https://ch.mathworks.com/matlabcentral/answers/867683-how-to-use-threads-in-matlab-app-designer/
https://ch.mathworks.com/matlabcentral/answers/1413247-threading-in-matlab-gui-callbacks
https://ch.mathworks.com/matlabcentral/answers/2164600-integrating-parallel-computing-with-app-designer-for-real-time-ui-updates
– https://www.mathworks.com/matlabcentral/answers/366576-will-there-be-a-support-of-the-parallel-toolbox-in-matlab-app-designer#comment_720548
https://ch.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.html
https://ch.mathworks.com/help/parallel-computing/parpool.html
https://ch.mathworks.com/help/parallel-computing/parallel.pool.pollabledataqueue.html
https://ch.mathworks.com/help/parallel-computing/receive-communications-on-workers.html
https://in.mathworks.com/matlabcentral/answers/1726505-proper-use-of-dataqueue-and-pollabledataqueue-inside-of-app-designer-class
Example code which can not be saved as .mlapp
classdef ExampleWorkflowAbortAsyn < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Abort2Button matlab.ui.control.StateButton
TextArea matlab.ui.control.TextArea
AbortButton matlab.ui.control.Button
StartButton matlab.ui.control.Button
end
properties (Access = public)
TCindex % Description
isPassed = false;
asycnWorker
dataQueue
clientQueue
helperClientQueue
end
methods (Static)
function receiveDataOnClient(data)
disp(data);
drawnow limitrate;
end
end
methods (Access = public)
function testExecutionMaster(app)
while strcmp(app.StartButton.Text, ‘Pause’)
app.isPassed = false;
updateUILog(app,sprintf(‘TC %i’, app.TCindex));
app.TCindex = app.TCindex + 1;
updateUILog(app,sprintf(‘tPrepare measurement…’));
pause(1)
updateUILog(app,sprintf(‘tExecute measurement…’));
pause(1)
updateUILog(app,sprintf(‘tAnalyze Measurement…’));
pause(1)
updateUILog(app,sprintf(‘t Test passed :)’));
app.isPassed = true;
end
end
function abortMeasurementAction(app)
% nice to have: pop up with abort error and instructions
updateUILog(app,’User triggerd abort starts’);
updateUILog(app,sprintf(‘tAll devices off’));
end
function updateUILog(app,message)
textArray = app.TextArea.Value;
textArray{end+1} = message;
app.TextArea.Value = textArray;
scroll(app.TextArea, ‘bottom’)
% createDiaryEntry(app, message)
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function EnterTestState(app, event)
switch app.StartButton.Text
case ‘Start’
app.StartButton.Text = ‘Pause’;
app.TCindex = 1;
asycnWorker = parpool(‘Threads’,1);
clientQueue = parallel.pool.DataQueue;
afterEach(clientQueue,@(data) app.receiveDataOnClient(data));
helperClientQueue = parallel.pool.PollableDataQueue;
temp = app.StartButton.Text;
wkrF = parallel.FevalFuture;
wkrF = parfeval(@testExecutionWorker,0,temp);
wkrQueue = poll(helperClientQueue,inf);
send(wkrQueue.Queue,"Start generating data");
case ‘Pause’
app.StartButton.Text = ‘Resume’;
updateUILog(app,’Test execution enters pause state’)
while ~app.isPassed
pause(0.2)
end
updateUILog(app,sprintf(‘Test execution paused at %i’, app.TCindex));
case ‘Resume’
app.StartButton.Text = ‘Pause’;
updateUILog(app,’Resume test execution’);
testExecutionMaster(app)
end
updateUILog(app,"End of EnterTestStateFunction")
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create StartButton
app.StartButton = uibutton(app.UIFigure, ‘push’);
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @EnterTestState, true);
app.StartButton.Position = [422 321 138 45];
app.StartButton.Text = ‘Start’;
% Create AbortButton
app.AbortButton = uibutton(app.UIFigure, ‘push’);
app.AbortButton.Position = [422 249 138 41];
app.AbortButton.Text = ‘Abort’;
% Create TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.Editable = ‘off’;
app.TextArea.Position = [60 28 475 168];
% Create Abort2Button
app.Abort2Button = uibutton(app.UIFigure, ‘state’);
app.Abort2Button.Text = ‘Abort2’;
app.Abort2Button.Position = [129 289 186 54];
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ExampleWorkflowAbortAsyn
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end Hello community
I want to use the Parallel Pool Box in App Designer to run a parallel thread and pass information between the two entitiies.
Imagine the following use case: You want to start, pause and abort i.e. a sequence of measurements from the GUI
In case the start is activated the start button changes to pause button and starts in parallel the measurement sequence.
In case the executions is paused, the current step of the sequence is allowed to be finished.
In case of abort the measurement shall be stopped immediatly and the instruments gracefully turned off.
I tried to represent this in a workflow (shown at end of post- file follows as soon as upload works again). And did setup a simplified .mlapp first trying to start a parallel thread queueing information and the main code fetching that information and diplaying it in a text area. But in that form I cannot save it as .mlapp file. From what I’ve read so far in the forum (see list below) it seems to be an issue of handing over the app object to the parallel process. But I don’t understand what I am doing wrong and thus think I missed an important part of the data queue handling. I would be glad for any hint/information/support to fix this issue and learn from that mistake.
Further information I checked prior to set up .mlapp:
https://ch.mathworks.com/matlabcentral/answers/867683-how-to-use-threads-in-matlab-app-designer/
https://ch.mathworks.com/matlabcentral/answers/1413247-threading-in-matlab-gui-callbacks
https://ch.mathworks.com/matlabcentral/answers/2164600-integrating-parallel-computing-with-app-designer-for-real-time-ui-updates
– https://www.mathworks.com/matlabcentral/answers/366576-will-there-be-a-support-of-the-parallel-toolbox-in-matlab-app-designer#comment_720548
https://ch.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.html
https://ch.mathworks.com/help/parallel-computing/parpool.html
https://ch.mathworks.com/help/parallel-computing/parallel.pool.pollabledataqueue.html
https://ch.mathworks.com/help/parallel-computing/receive-communications-on-workers.html
https://in.mathworks.com/matlabcentral/answers/1726505-proper-use-of-dataqueue-and-pollabledataqueue-inside-of-app-designer-class
Example code which can not be saved as .mlapp
classdef ExampleWorkflowAbortAsyn < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Abort2Button matlab.ui.control.StateButton
TextArea matlab.ui.control.TextArea
AbortButton matlab.ui.control.Button
StartButton matlab.ui.control.Button
end
properties (Access = public)
TCindex % Description
isPassed = false;
asycnWorker
dataQueue
clientQueue
helperClientQueue
end
methods (Static)
function receiveDataOnClient(data)
disp(data);
drawnow limitrate;
end
end
methods (Access = public)
function testExecutionMaster(app)
while strcmp(app.StartButton.Text, ‘Pause’)
app.isPassed = false;
updateUILog(app,sprintf(‘TC %i’, app.TCindex));
app.TCindex = app.TCindex + 1;
updateUILog(app,sprintf(‘tPrepare measurement…’));
pause(1)
updateUILog(app,sprintf(‘tExecute measurement…’));
pause(1)
updateUILog(app,sprintf(‘tAnalyze Measurement…’));
pause(1)
updateUILog(app,sprintf(‘t Test passed :)’));
app.isPassed = true;
end
end
function abortMeasurementAction(app)
% nice to have: pop up with abort error and instructions
updateUILog(app,’User triggerd abort starts’);
updateUILog(app,sprintf(‘tAll devices off’));
end
function updateUILog(app,message)
textArray = app.TextArea.Value;
textArray{end+1} = message;
app.TextArea.Value = textArray;
scroll(app.TextArea, ‘bottom’)
% createDiaryEntry(app, message)
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function EnterTestState(app, event)
switch app.StartButton.Text
case ‘Start’
app.StartButton.Text = ‘Pause’;
app.TCindex = 1;
asycnWorker = parpool(‘Threads’,1);
clientQueue = parallel.pool.DataQueue;
afterEach(clientQueue,@(data) app.receiveDataOnClient(data));
helperClientQueue = parallel.pool.PollableDataQueue;
temp = app.StartButton.Text;
wkrF = parallel.FevalFuture;
wkrF = parfeval(@testExecutionWorker,0,temp);
wkrQueue = poll(helperClientQueue,inf);
send(wkrQueue.Queue,"Start generating data");
case ‘Pause’
app.StartButton.Text = ‘Resume’;
updateUILog(app,’Test execution enters pause state’)
while ~app.isPassed
pause(0.2)
end
updateUILog(app,sprintf(‘Test execution paused at %i’, app.TCindex));
case ‘Resume’
app.StartButton.Text = ‘Pause’;
updateUILog(app,’Resume test execution’);
testExecutionMaster(app)
end
updateUILog(app,"End of EnterTestStateFunction")
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create StartButton
app.StartButton = uibutton(app.UIFigure, ‘push’);
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @EnterTestState, true);
app.StartButton.Position = [422 321 138 45];
app.StartButton.Text = ‘Start’;
% Create AbortButton
app.AbortButton = uibutton(app.UIFigure, ‘push’);
app.AbortButton.Position = [422 249 138 41];
app.AbortButton.Text = ‘Abort’;
% Create TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.Editable = ‘off’;
app.TextArea.Position = [60 28 475 168];
% Create Abort2Button
app.Abort2Button = uibutton(app.UIFigure, ‘state’);
app.Abort2Button.Text = ‘Abort2’;
app.Abort2Button.Position = [129 289 186 54];
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ExampleWorkflowAbortAsyn
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end appdesigner, parallel computing toolbox, dataqueue, asynchronous MATLAB Answers — New Questions