Tag Archives: matlab
How to measure impedance in low voltage circuits
Hi there,
I need some help at the following model. I woud like to measure the impedance of the circuit. I tried by measuring V and I and then analyze their quotient by using ‘Linear Analysisi Points’ however, I haven’t found such option when selecting the lines (i.e. Input or Voltage) and clicking right mouse’s button.
Have I missed sth? I already installed Linear System Analyzer app, I’m not sure wether it help, though. If you have any other preposition please let me know.Hi there,
I need some help at the following model. I woud like to measure the impedance of the circuit. I tried by measuring V and I and then analyze their quotient by using ‘Linear Analysisi Points’ however, I haven’t found such option when selecting the lines (i.e. Input or Voltage) and clicking right mouse’s button.
Have I missed sth? I already installed Linear System Analyzer app, I’m not sure wether it help, though. If you have any other preposition please let me know. Hi there,
I need some help at the following model. I woud like to measure the impedance of the circuit. I tried by measuring V and I and then analyze their quotient by using ‘Linear Analysisi Points’ however, I haven’t found such option when selecting the lines (i.e. Input or Voltage) and clicking right mouse’s button.
Have I missed sth? I already installed Linear System Analyzer app, I’m not sure wether it help, though. If you have any other preposition please let me know. linear analysis points, impedance measurement MATLAB Answers — New Questions
Why do i only get 1 of 2 roots of this function when using Newtons method? What am i missing?
disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x;disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x; disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x; finding roots, newtons method, matlab MATLAB Answers — New Questions
Training in programming FPGAs in Matlab/Simulink using examples: from simple to complex
Hi!
I’m a beginner and want to learn FPGA programming. I was very attracted by the possibility of interconnected work of Matlab/Simulink with codes for FPGAs, as well as the possibility of testing algorithms developed for FPGAs in Matlab/Simulink.
I have a certain idea in the spirit of: “We place the element/elements in Simulink, convert it into one of the languages VHDL/Verilog/etc., sew it into the FPGA or into the FPGA simulation program, debug and complete the project” or vice versa “We write the program on VHDL/Verilog, copy the code into Simulink, assemble the circuit, simulate".
I would like to try to do something on my own, but unfortunately there are several blind spots in my idea, namely: the sequence of the conversion process in Simulink; it is unclear how both a digital circuit and PID control can be embedded in an FPGA; is it possible to convert any block from Simulink into the FPGA code.
As the first two projects I would like to implement the following:
1. Simple asynchronous RS-trigger.
2. A simple PID-controller to control the output of an aperiodic link with a transfer function .
I’m asking for some advice on how to do this. I’ll practice. I would be very grateful and grateful for your help in overcoming this milestone.Hi!
I’m a beginner and want to learn FPGA programming. I was very attracted by the possibility of interconnected work of Matlab/Simulink with codes for FPGAs, as well as the possibility of testing algorithms developed for FPGAs in Matlab/Simulink.
I have a certain idea in the spirit of: “We place the element/elements in Simulink, convert it into one of the languages VHDL/Verilog/etc., sew it into the FPGA or into the FPGA simulation program, debug and complete the project” or vice versa “We write the program on VHDL/Verilog, copy the code into Simulink, assemble the circuit, simulate".
I would like to try to do something on my own, but unfortunately there are several blind spots in my idea, namely: the sequence of the conversion process in Simulink; it is unclear how both a digital circuit and PID control can be embedded in an FPGA; is it possible to convert any block from Simulink into the FPGA code.
As the first two projects I would like to implement the following:
1. Simple asynchronous RS-trigger.
2. A simple PID-controller to control the output of an aperiodic link with a transfer function .
I’m asking for some advice on how to do this. I’ll practice. I would be very grateful and grateful for your help in overcoming this milestone. Hi!
I’m a beginner and want to learn FPGA programming. I was very attracted by the possibility of interconnected work of Matlab/Simulink with codes for FPGAs, as well as the possibility of testing algorithms developed for FPGAs in Matlab/Simulink.
I have a certain idea in the spirit of: “We place the element/elements in Simulink, convert it into one of the languages VHDL/Verilog/etc., sew it into the FPGA or into the FPGA simulation program, debug and complete the project” or vice versa “We write the program on VHDL/Verilog, copy the code into Simulink, assemble the circuit, simulate".
I would like to try to do something on my own, but unfortunately there are several blind spots in my idea, namely: the sequence of the conversion process in Simulink; it is unclear how both a digital circuit and PID control can be embedded in an FPGA; is it possible to convert any block from Simulink into the FPGA code.
As the first two projects I would like to implement the following:
1. Simple asynchronous RS-trigger.
2. A simple PID-controller to control the output of an aperiodic link with a transfer function .
I’m asking for some advice on how to do this. I’ll practice. I would be very grateful and grateful for your help in overcoming this milestone. fpga, pld, logical elements, vhdl, verilog, rs-trigger, pid-control MATLAB Answers — New Questions
Matlab select query incorrectly handling null
Running a simple mysql select query (select * from table) using the SELECT(CONN,QUERY) command. If I run the query through the command line I can view the data as expected. There are a few columns where every value is null which is correct for the data. If I run the query through the Matlab select command all row columns except one return as expected. One column instead of reading all NULL as it should, returns all -2147483648. Any help is appreciated.Running a simple mysql select query (select * from table) using the SELECT(CONN,QUERY) command. If I run the query through the command line I can view the data as expected. There are a few columns where every value is null which is correct for the data. If I run the query through the Matlab select command all row columns except one return as expected. One column instead of reading all NULL as it should, returns all -2147483648. Any help is appreciated. Running a simple mysql select query (select * from table) using the SELECT(CONN,QUERY) command. If I run the query through the command line I can view the data as expected. There are a few columns where every value is null which is correct for the data. If I run the query through the Matlab select command all row columns except one return as expected. One column instead of reading all NULL as it should, returns all -2147483648. Any help is appreciated. mysql matlab MATLAB Answers — New Questions
initialize persistent variables using Matlab coder
My Matlab code utilizes a few persistent variables and currently uses "isempty" for one of the variables to ensure all are intialized before use. The resulting Matlab coder initialization function sets a bool "var_isempty". This seems rather clunky. To me it seems that the appropriate coder output should instead initialize the values in the static variable definition within the function.
Is there a codegen option to generate the code in this manner? Or another way?
The https://www.mathworks.com/help/coder/ug/use-generated-initialize-and-terminate-functions.html refers to both global and persistent variables witht the -global option. Is this the best method?My Matlab code utilizes a few persistent variables and currently uses "isempty" for one of the variables to ensure all are intialized before use. The resulting Matlab coder initialization function sets a bool "var_isempty". This seems rather clunky. To me it seems that the appropriate coder output should instead initialize the values in the static variable definition within the function.
Is there a codegen option to generate the code in this manner? Or another way?
The https://www.mathworks.com/help/coder/ug/use-generated-initialize-and-terminate-functions.html refers to both global and persistent variables witht the -global option. Is this the best method? My Matlab code utilizes a few persistent variables and currently uses "isempty" for one of the variables to ensure all are intialized before use. The resulting Matlab coder initialization function sets a bool "var_isempty". This seems rather clunky. To me it seems that the appropriate coder output should instead initialize the values in the static variable definition within the function.
Is there a codegen option to generate the code in this manner? Or another way?
The https://www.mathworks.com/help/coder/ug/use-generated-initialize-and-terminate-functions.html refers to both global and persistent variables witht the -global option. Is this the best method? matlab coder, persistent variables, initialization MATLAB Answers — New Questions
Cant open property inspector in MAtlab online
I am using MAtlab online and once i make a surface plot. I click on the property inspector, I even tried writing inspect in the command window but it keeps on loading and does not open.I am using MAtlab online and once i make a surface plot. I click on the property inspector, I even tried writing inspect in the command window but it keeps on loading and does not open. I am using MAtlab online and once i make a surface plot. I click on the property inspector, I even tried writing inspect in the command window but it keeps on loading and does not open. property inspector, surface plots, 3d plots MATLAB Answers — New Questions
MATLAB Function Coder error
Does anyone know how to resolve this error?
「Cannot call function.」
「During code generation, the integer input or result class of TYPECAST must map directly to C types on the target hardware. Class uint64 does not map to 64-bit C types.」Does anyone know how to resolve this error?
「Cannot call function.」
「During code generation, the integer input or result class of TYPECAST must map directly to C types on the target hardware. Class uint64 does not map to 64-bit C types.」 Does anyone know how to resolve this error?
「Cannot call function.」
「During code generation, the integer input or result class of TYPECAST must map directly to C types on the target hardware. Class uint64 does not map to 64-bit C types.」 matlab function, matlab coder, c++, compiler MATLAB Answers — New Questions
Why does my fit to a PDF generated using a histogram not add up to 1 or give me correct expected value?
Hello,
I generate a pdf from a histogram which describes the distribution of values about an average. For example say I have values {x1,x2,….xn}, my PDF is to see how x’={x1,x2,….xn}/mean({x1,x2,….xn}) is distributed.
The PDF of x’ (blue curve) i generated is shown below where I fit a yellow quadratic function to whatever is below the mean <1 and with an exponential fit to whatever is >1.If I sum the blue curve:
(sum(prob))
it is 1 which makes sense since probabilities should add up to 1. In addition, if I do:
sum(x’.*prob)
for the distribution, I get 1 which makes sense because my expected value should be 1. However, If I try to do the same with my curve fits, using trapezoidal integration, I do not get 1! I don’t understand what is missing.. am I not normalizing a quantity?
The full code snippet I used to generate the above figure is attached below. I have also attached the data to this post if you might be interested in taking a look. My expected value from the discrete distribution given by the variable ‘discrete’ is nearly 1. but the ‘continuous’ variable when computed is like 0.18 which is unexpected. Any help is much appreciated!
data = [data_tot_fn_4_0p05/mean(data_tot_fn_4_0p05)]; %# Sample data
xRange = 0:0.2:max(data); %# Range of integers to compute a probability for
N = hist(data,xRange); %# Bin the data
prob=N./numel(data);
semilogy(xRange,prob); %# Plot the probabilities for each integer
xlabel(‘Integer value’);
ylabel(‘Probability’);
greater1=find(xRange>=1);
xgreater1=xRange(greater1)
ygreater1=prob(greater1);
less1=find(xRange<=1);
xless1=xRange(less1)
yless1=prob(less1);
model = @(a, x) exp(-a*(x));
% Initial guess for the parameter ‘a’
initial_guess = 0.5;
% Perform the curve fitting
a_fitgreat = lsqcurvefit(model, initial_guess, xgreater1, ygreater1);
model2=@(p,x)p(1)+p(2)./(p(3).*sqrt(pi/2)).*exp(-2*(x-p(4)).^2./p(3).^2)
model2=@(p,x)p(1)+p(2).*x+p(3).*x.^2;
initial_guess = [0.5,0.5,0.5,0.5];
initial_guess=[0.5,0.5,0.5];
% Perform the curve fitting
a_fitless = lsqcurvefit(model2, initial_guess, xless1, yless1);
% Calculate the fitted curve using the optimized ‘a’ value
y_fit_great = model(a_fitgreat, xgreater1);
y_fit_less = model2(a_fitless, xless1);
hold on;
plot(xgreater1,y_fit_great);
hold on;
plot(xless1,y_fit_less)
discrete=sum(xRange.*prob)
continuous=trapz(fofaveless,(fofaveless).*yfofaveless)+trapz(fofavegreat,(fofavegreat).*yfofavegreat);Hello,
I generate a pdf from a histogram which describes the distribution of values about an average. For example say I have values {x1,x2,….xn}, my PDF is to see how x’={x1,x2,….xn}/mean({x1,x2,….xn}) is distributed.
The PDF of x’ (blue curve) i generated is shown below where I fit a yellow quadratic function to whatever is below the mean <1 and with an exponential fit to whatever is >1.If I sum the blue curve:
(sum(prob))
it is 1 which makes sense since probabilities should add up to 1. In addition, if I do:
sum(x’.*prob)
for the distribution, I get 1 which makes sense because my expected value should be 1. However, If I try to do the same with my curve fits, using trapezoidal integration, I do not get 1! I don’t understand what is missing.. am I not normalizing a quantity?
The full code snippet I used to generate the above figure is attached below. I have also attached the data to this post if you might be interested in taking a look. My expected value from the discrete distribution given by the variable ‘discrete’ is nearly 1. but the ‘continuous’ variable when computed is like 0.18 which is unexpected. Any help is much appreciated!
data = [data_tot_fn_4_0p05/mean(data_tot_fn_4_0p05)]; %# Sample data
xRange = 0:0.2:max(data); %# Range of integers to compute a probability for
N = hist(data,xRange); %# Bin the data
prob=N./numel(data);
semilogy(xRange,prob); %# Plot the probabilities for each integer
xlabel(‘Integer value’);
ylabel(‘Probability’);
greater1=find(xRange>=1);
xgreater1=xRange(greater1)
ygreater1=prob(greater1);
less1=find(xRange<=1);
xless1=xRange(less1)
yless1=prob(less1);
model = @(a, x) exp(-a*(x));
% Initial guess for the parameter ‘a’
initial_guess = 0.5;
% Perform the curve fitting
a_fitgreat = lsqcurvefit(model, initial_guess, xgreater1, ygreater1);
model2=@(p,x)p(1)+p(2)./(p(3).*sqrt(pi/2)).*exp(-2*(x-p(4)).^2./p(3).^2)
model2=@(p,x)p(1)+p(2).*x+p(3).*x.^2;
initial_guess = [0.5,0.5,0.5,0.5];
initial_guess=[0.5,0.5,0.5];
% Perform the curve fitting
a_fitless = lsqcurvefit(model2, initial_guess, xless1, yless1);
% Calculate the fitted curve using the optimized ‘a’ value
y_fit_great = model(a_fitgreat, xgreater1);
y_fit_less = model2(a_fitless, xless1);
hold on;
plot(xgreater1,y_fit_great);
hold on;
plot(xless1,y_fit_less)
discrete=sum(xRange.*prob)
continuous=trapz(fofaveless,(fofaveless).*yfofaveless)+trapz(fofavegreat,(fofavegreat).*yfofavegreat); Hello,
I generate a pdf from a histogram which describes the distribution of values about an average. For example say I have values {x1,x2,….xn}, my PDF is to see how x’={x1,x2,….xn}/mean({x1,x2,….xn}) is distributed.
The PDF of x’ (blue curve) i generated is shown below where I fit a yellow quadratic function to whatever is below the mean <1 and with an exponential fit to whatever is >1.If I sum the blue curve:
(sum(prob))
it is 1 which makes sense since probabilities should add up to 1. In addition, if I do:
sum(x’.*prob)
for the distribution, I get 1 which makes sense because my expected value should be 1. However, If I try to do the same with my curve fits, using trapezoidal integration, I do not get 1! I don’t understand what is missing.. am I not normalizing a quantity?
The full code snippet I used to generate the above figure is attached below. I have also attached the data to this post if you might be interested in taking a look. My expected value from the discrete distribution given by the variable ‘discrete’ is nearly 1. but the ‘continuous’ variable when computed is like 0.18 which is unexpected. Any help is much appreciated!
data = [data_tot_fn_4_0p05/mean(data_tot_fn_4_0p05)]; %# Sample data
xRange = 0:0.2:max(data); %# Range of integers to compute a probability for
N = hist(data,xRange); %# Bin the data
prob=N./numel(data);
semilogy(xRange,prob); %# Plot the probabilities for each integer
xlabel(‘Integer value’);
ylabel(‘Probability’);
greater1=find(xRange>=1);
xgreater1=xRange(greater1)
ygreater1=prob(greater1);
less1=find(xRange<=1);
xless1=xRange(less1)
yless1=prob(less1);
model = @(a, x) exp(-a*(x));
% Initial guess for the parameter ‘a’
initial_guess = 0.5;
% Perform the curve fitting
a_fitgreat = lsqcurvefit(model, initial_guess, xgreater1, ygreater1);
model2=@(p,x)p(1)+p(2)./(p(3).*sqrt(pi/2)).*exp(-2*(x-p(4)).^2./p(3).^2)
model2=@(p,x)p(1)+p(2).*x+p(3).*x.^2;
initial_guess = [0.5,0.5,0.5,0.5];
initial_guess=[0.5,0.5,0.5];
% Perform the curve fitting
a_fitless = lsqcurvefit(model2, initial_guess, xless1, yless1);
% Calculate the fitted curve using the optimized ‘a’ value
y_fit_great = model(a_fitgreat, xgreater1);
y_fit_less = model2(a_fitless, xless1);
hold on;
plot(xgreater1,y_fit_great);
hold on;
plot(xless1,y_fit_less)
discrete=sum(xRange.*prob)
continuous=trapz(fofaveless,(fofaveless).*yfofaveless)+trapz(fofavegreat,(fofavegreat).*yfofavegreat); pdf, histogram, integral, sum, probability MATLAB Answers — New Questions
Can you place ui-components in uigridlayout using Name-Value pair input?
uif = uifigure;
uig = uigridlayout(‘Parent’, uif, …
‘ColumnWidth’, repmat({‘1x’}, 1, 5), …
‘RowHeight’, repmat({‘1x’}, 1, 3));
uib = uibutton(‘Parent’, uig, …
‘Text’, ‘I want to be placed in one line’)
% Put this lines inside ‘uibutton’ initialisation:
uib.Layout.Column = 3;
uib.Layout.Row = 2;
I searched for something able to create an instance of GridLayoutOptions, but i can’t find anything.
An alternative would be to understand how matlab.ui.layout.LayoutOptions would accept inputs.uif = uifigure;
uig = uigridlayout(‘Parent’, uif, …
‘ColumnWidth’, repmat({‘1x’}, 1, 5), …
‘RowHeight’, repmat({‘1x’}, 1, 3));
uib = uibutton(‘Parent’, uig, …
‘Text’, ‘I want to be placed in one line’)
% Put this lines inside ‘uibutton’ initialisation:
uib.Layout.Column = 3;
uib.Layout.Row = 2;
I searched for something able to create an instance of GridLayoutOptions, but i can’t find anything.
An alternative would be to understand how matlab.ui.layout.LayoutOptions would accept inputs. uif = uifigure;
uig = uigridlayout(‘Parent’, uif, …
‘ColumnWidth’, repmat({‘1x’}, 1, 5), …
‘RowHeight’, repmat({‘1x’}, 1, 3));
uib = uibutton(‘Parent’, uig, …
‘Text’, ‘I want to be placed in one line’)
% Put this lines inside ‘uibutton’ initialisation:
uib.Layout.Column = 3;
uib.Layout.Row = 2;
I searched for something able to create an instance of GridLayoutOptions, but i can’t find anything.
An alternative would be to understand how matlab.ui.layout.LayoutOptions would accept inputs. uigridlayout MATLAB Answers — New Questions
Why do I receive error LNK1104: cannot open file libboost_zlib-vc142-mt-x64-1_84.lib
I receive "error LNK1104: cannot open file libboost_zlib-vc142-mt-x64-1_84.lib" when I run following code
mex -v "D:csvfilehubsfastTableReadV3.cpp" -ID:boost_1_84_0 -LD:boost_1_84_0stagelib
I find the file "libboost_zlib-vc142-mt-x64-1_84.lib" in "D:boost_1_84_0stagelib". I can’t figure out why it still have this error.I receive "error LNK1104: cannot open file libboost_zlib-vc142-mt-x64-1_84.lib" when I run following code
mex -v "D:csvfilehubsfastTableReadV3.cpp" -ID:boost_1_84_0 -LD:boost_1_84_0stagelib
I find the file "libboost_zlib-vc142-mt-x64-1_84.lib" in "D:boost_1_84_0stagelib". I can’t figure out why it still have this error. I receive "error LNK1104: cannot open file libboost_zlib-vc142-mt-x64-1_84.lib" when I run following code
mex -v "D:csvfilehubsfastTableReadV3.cpp" -ID:boost_1_84_0 -LD:boost_1_84_0stagelib
I find the file "libboost_zlib-vc142-mt-x64-1_84.lib" in "D:boost_1_84_0stagelib". I can’t figure out why it still have this error. mex, mex compiler MATLAB Answers — New Questions
Figure in shrunk on screen when dimensions are set for publishing
I want to create a figure of 5 x 5 cm to insert as a panel on a larger figure for academic publishing. I would like to set the fontsize in matlab so that it is consistent across panels (ie. 8). I could for example export the figure with exportgraphics and rescale the figure in an image editor but then, the fontsize ends up being scaled also, which I do not want.
My problem is that if I set the figure dimension to 5×5, its appearance on the screen (4K resolution) becomes very small (spanning around 100 x 100 pixels on screen). I would like to be able to scale the figure displayed on the screen so that the 5 x 5 cm figure spans say 1000 x 1000 pixels (similar as in a pdf which you would open and zoom in).I want to create a figure of 5 x 5 cm to insert as a panel on a larger figure for academic publishing. I would like to set the fontsize in matlab so that it is consistent across panels (ie. 8). I could for example export the figure with exportgraphics and rescale the figure in an image editor but then, the fontsize ends up being scaled also, which I do not want.
My problem is that if I set the figure dimension to 5×5, its appearance on the screen (4K resolution) becomes very small (spanning around 100 x 100 pixels on screen). I would like to be able to scale the figure displayed on the screen so that the 5 x 5 cm figure spans say 1000 x 1000 pixels (similar as in a pdf which you would open and zoom in). I want to create a figure of 5 x 5 cm to insert as a panel on a larger figure for academic publishing. I would like to set the fontsize in matlab so that it is consistent across panels (ie. 8). I could for example export the figure with exportgraphics and rescale the figure in an image editor but then, the fontsize ends up being scaled also, which I do not want.
My problem is that if I set the figure dimension to 5×5, its appearance on the screen (4K resolution) becomes very small (spanning around 100 x 100 pixels on screen). I would like to be able to scale the figure displayed on the screen so that the 5 x 5 cm figure spans say 1000 x 1000 pixels (similar as in a pdf which you would open and zoom in). figure, export MATLAB Answers — New Questions
Creating a 2D Lookup Table for PMSM in EV Applications Using Simulink
Hello MATLAB Simulink Community,
I am currently working on developing a 2D Lookup Table for a Permanent Magnet Synchronous Motor (PMSM) to optimize its operation in an electric vehicle (EV). My objective is to collect data on motor torque, Vde (d-axis voltage), and Vqe (q-axis voltage) under conditions of limited back-EMF WHILE changing Beta-angle and stator Current. This data collection is critical for optimizing motor control strategies(MTPA, Field-Weakening control)
Here are the specific aspects I need help with:
Speed Control Setup: I need to implement a control system in Simulink that allows the PMSM to operate at set speeds to run with limited back-EMF. Which blocks or models would be best for controlling speed of a PMSM regardless of current of PMSM in Simulink?
Data Collection for LUT: As the motor runs, I need to systematically record the torque, Vde, and Vqe. What are the best practices for setting up data logging in Simulink for these variables, especially considering the impacts of limited back-EMF?
Lookup Table Generation: Any advice on how to automate the generation of a 2D LUT based on the collected data within Simulink would be greatly appreciated.
Could you please provide guidance or suggest resources, blocks, or toolkits in Simulink that could be useful for these purposes? Additionally, if there are example models or tutorials related to advanced PMSM control, including speed control and regenerative braking, those would be very helpful.
Thank you in advance for your assistance!Hello MATLAB Simulink Community,
I am currently working on developing a 2D Lookup Table for a Permanent Magnet Synchronous Motor (PMSM) to optimize its operation in an electric vehicle (EV). My objective is to collect data on motor torque, Vde (d-axis voltage), and Vqe (q-axis voltage) under conditions of limited back-EMF WHILE changing Beta-angle and stator Current. This data collection is critical for optimizing motor control strategies(MTPA, Field-Weakening control)
Here are the specific aspects I need help with:
Speed Control Setup: I need to implement a control system in Simulink that allows the PMSM to operate at set speeds to run with limited back-EMF. Which blocks or models would be best for controlling speed of a PMSM regardless of current of PMSM in Simulink?
Data Collection for LUT: As the motor runs, I need to systematically record the torque, Vde, and Vqe. What are the best practices for setting up data logging in Simulink for these variables, especially considering the impacts of limited back-EMF?
Lookup Table Generation: Any advice on how to automate the generation of a 2D LUT based on the collected data within Simulink would be greatly appreciated.
Could you please provide guidance or suggest resources, blocks, or toolkits in Simulink that could be useful for these purposes? Additionally, if there are example models or tutorials related to advanced PMSM control, including speed control and regenerative braking, those would be very helpful.
Thank you in advance for your assistance! Hello MATLAB Simulink Community,
I am currently working on developing a 2D Lookup Table for a Permanent Magnet Synchronous Motor (PMSM) to optimize its operation in an electric vehicle (EV). My objective is to collect data on motor torque, Vde (d-axis voltage), and Vqe (q-axis voltage) under conditions of limited back-EMF WHILE changing Beta-angle and stator Current. This data collection is critical for optimizing motor control strategies(MTPA, Field-Weakening control)
Here are the specific aspects I need help with:
Speed Control Setup: I need to implement a control system in Simulink that allows the PMSM to operate at set speeds to run with limited back-EMF. Which blocks or models would be best for controlling speed of a PMSM regardless of current of PMSM in Simulink?
Data Collection for LUT: As the motor runs, I need to systematically record the torque, Vde, and Vqe. What are the best practices for setting up data logging in Simulink for these variables, especially considering the impacts of limited back-EMF?
Lookup Table Generation: Any advice on how to automate the generation of a 2D LUT based on the collected data within Simulink would be greatly appreciated.
Could you please provide guidance or suggest resources, blocks, or toolkits in Simulink that could be useful for these purposes? Additionally, if there are example models or tutorials related to advanced PMSM control, including speed control and regenerative braking, those would be very helpful.
Thank you in advance for your assistance! mtpa, field weakening, pmsm MATLAB Answers — New Questions
Is there a way to turn a subsystem that exists inside a slx file to its respective time tasks?
Is there a way to turn a subsystem that exists inside a slx file to its respective time tasks?
ex) one of them task is 10ms, other task is 20ms….Is there a way to turn a subsystem that exists inside a slx file to its respective time tasks?
ex) one of them task is 10ms, other task is 20ms…. Is there a way to turn a subsystem that exists inside a slx file to its respective time tasks?
ex) one of them task is 10ms, other task is 20ms…. simulink, matlab MATLAB Answers — New Questions
4 walls vs 1 wall – House regulation on heating
Hi MathWorks team,
While studyin a House Heating system, I failed to understand why would the model of the house only have one wall insted of 4 walls and a floor ? (House Heating System)
I’m trying to model my own model on this theme, that is a room heating system for starters.
The model from MathWorks
The idea of a model I have in mindHi MathWorks team,
While studyin a House Heating system, I failed to understand why would the model of the house only have one wall insted of 4 walls and a floor ? (House Heating System)
I’m trying to model my own model on this theme, that is a room heating system for starters.
The model from MathWorks
The idea of a model I have in mind Hi MathWorks team,
While studyin a House Heating system, I failed to understand why would the model of the house only have one wall insted of 4 walls and a floor ? (House Heating System)
I’m trying to model my own model on this theme, that is a room heating system for starters.
The model from MathWorks
The idea of a model I have in mind house, heating, cooling, thermal control, temperature regulation, simscape, room heating MATLAB Answers — New Questions
Error in sending mail through matlab
Im trying to send a mail through matlab but im keep getting this error
my code was like
mail = ‘myuniversitymail@univ.edu’;
password = ‘mypassword’;
mailingList = {‘receivermail@gmail.com’};
server = ‘smtp-mail.outlook.com’;
props = java.lang.System.getProperties;
props.setProperty(‘mail.smtp.port’,’587′);
props.setProperty(‘mail.smtp.starttls.enable’,’true’);
props.setProperty(‘mail.smtp.ssl.trust’, ‘*’)
setpref(‘Internet’,’E_mail’,mail);
setpref(‘Internet’,’SMTP_Server’,server);
setpref(‘Internet’,’SMTP_Username’,mail);
setpref(‘Internet’,’SMTP_Password’,password);
messageBody = sprintf(‘ Good morning ‘);
messageBody = sprintf(‘%snn Here is the data analysis from yesterdays data. Have a great day!’, messageBody);
messageBody = sprintf(‘%snnn *This email was generated and sent automatically via MATLAB’, messageBody);
sendmail(mailingList,"Data Analysis",messageBody,filename);
And the error is like,
Error using sendmail (line 184)
Can’t send command to SMTP host;
No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Error in project (line 73)
sendmail(mailingList,"Data Analysis",messageBody,filename);
Pls help me to resolve this issue asap….Im trying to send a mail through matlab but im keep getting this error
my code was like
mail = ‘myuniversitymail@univ.edu’;
password = ‘mypassword’;
mailingList = {‘receivermail@gmail.com’};
server = ‘smtp-mail.outlook.com’;
props = java.lang.System.getProperties;
props.setProperty(‘mail.smtp.port’,’587′);
props.setProperty(‘mail.smtp.starttls.enable’,’true’);
props.setProperty(‘mail.smtp.ssl.trust’, ‘*’)
setpref(‘Internet’,’E_mail’,mail);
setpref(‘Internet’,’SMTP_Server’,server);
setpref(‘Internet’,’SMTP_Username’,mail);
setpref(‘Internet’,’SMTP_Password’,password);
messageBody = sprintf(‘ Good morning ‘);
messageBody = sprintf(‘%snn Here is the data analysis from yesterdays data. Have a great day!’, messageBody);
messageBody = sprintf(‘%snnn *This email was generated and sent automatically via MATLAB’, messageBody);
sendmail(mailingList,"Data Analysis",messageBody,filename);
And the error is like,
Error using sendmail (line 184)
Can’t send command to SMTP host;
No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Error in project (line 73)
sendmail(mailingList,"Data Analysis",messageBody,filename);
Pls help me to resolve this issue asap…. Im trying to send a mail through matlab but im keep getting this error
my code was like
mail = ‘myuniversitymail@univ.edu’;
password = ‘mypassword’;
mailingList = {‘receivermail@gmail.com’};
server = ‘smtp-mail.outlook.com’;
props = java.lang.System.getProperties;
props.setProperty(‘mail.smtp.port’,’587′);
props.setProperty(‘mail.smtp.starttls.enable’,’true’);
props.setProperty(‘mail.smtp.ssl.trust’, ‘*’)
setpref(‘Internet’,’E_mail’,mail);
setpref(‘Internet’,’SMTP_Server’,server);
setpref(‘Internet’,’SMTP_Username’,mail);
setpref(‘Internet’,’SMTP_Password’,password);
messageBody = sprintf(‘ Good morning ‘);
messageBody = sprintf(‘%snn Here is the data analysis from yesterdays data. Have a great day!’, messageBody);
messageBody = sprintf(‘%snnn *This email was generated and sent automatically via MATLAB’, messageBody);
sendmail(mailingList,"Data Analysis",messageBody,filename);
And the error is like,
Error using sendmail (line 184)
Can’t send command to SMTP host;
No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Error in project (line 73)
sendmail(mailingList,"Data Analysis",messageBody,filename);
Pls help me to resolve this issue asap…. matlab error, sendmail error, smtp host, sendmail, mail MATLAB Answers — New Questions
different color to plot
hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black)hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black) hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black) different color to plot MATLAB Answers — New Questions
Index exceeds the number of array elements. Index must not exceed 1.
%% Design Project Part 2
% 2.1
% Constants:
kapp = 0.009; % m^3/mol*min
L = 1; % m
Vtot = 0.25; % m^3
FT0 = 20; % mol/ min
v0 = 0.08; % m^3/min
P = 100; % atm
rho = 4.2; % kg/m^3
mu = 0.492*10^-5; % kg/m*s
dp = 0.015; % m
phi = 0.75; % ?
km = 4; % 1/min
Fsg0 = 0.1; % mol/min
% Cases:
vsg0 = 0.1; % m^3/min
%vsg0 = 0.001; % m^3/min
v = @(FA, FB, FR, FP) ((v0/FT0)*(FA+FB+FR+FP));
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
CA = @(FA, FB, FR, FP) FA/v(FA, FB, FR, FP);
CB = @(FA, FB, FR, FP) FB/v(FA, FB, FR, FP);
CP = @(FA, FB, FR, FP) FP/v(FA, FB, FR, FP);
CR = @(FA, FB, FR, FP) FR/v(FA, FB, FR, FP);
CPsg = @(FPsg) FPsg/vsg(FPsg);
dFAdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFBdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFRdV = @(FA, FB, FR, FP) -kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
dFpsgdV = @(FPsg, FP) km(CP-CPsg);
FA = 10; % mol/ min
FB = 10; % mol/ min
FR = 0; % mol/ min
FP = 0; % mol/ min
FPsg = 0.1; % mol/min
dV = 0.01;
Vlim = 0.25;
Vspan = 0:dV:Vlim;
CA_values = zeros(size(Vspan));
CB_values = zeros(size(Vspan));
CP_values = zeros(size(Vspan));
CR_values = zeros(size(Vspan));
CPsg_values = zeros(size(Vspan));
FA_values = zeros(size(Vspan));
FB_values = zeros(size(Vspan));
FR_values = zeros(size(Vspan));
FP_values = zeros(size(Vspan));
FPsg_values = zeros(size(Vspan));
for i=1:length(Vspan)
dFA = dFAdV(FA, FB, FR, FP);
dFB = dFBdV(FA, FB, FR, FP);
dFR = dFRdV(FA, FB, FR, FP);
dFP = dFPdV(FPsg, FA, FB, FP, FR);
dFPsg = dFPsgdV(Fpsg, FP);
CA_values(i) = CA(FA, FB, FR, FP);
CB_values(i) = CB(FA, FB, FR, FP);
CP_values(i) = CP(FA, FB, FR, FP);
CR_values(i) = CR(FA, FB, FR, FP);
CPsg_values(i) = CPsg(Fpsg);
dFA = FA+dFA*dV;
dFB = FB+dFB*dV;
dFR = FR+dFR*dV;
dFP = FP+dFP*dV;
dFPsg = FPsg+dFPsg*dV;
FA_values(i) = FA;
FB_values(i) = FB;
FR_values(i) = FR;
FP_values(i) = FP;
FPsg_values(i) = FPsg;
end
figure()
hold on;
plot(Vspan, FA_values,’LineWidth’, 2);
plot(Vspan, FB_values,’LineWidth’, 2);
plot(Vspan, FP_values,’LineWidth’, 2);
plot(Vspan, FR_values,’LineWidth’, 2);
plot(Vspan, FPsg_values,’LineWidth’, 2);
xlabel(‘PBR volume V [=] m^3’);
ylabel(‘f(V) [=] mol/min’);
set(gca, ‘LineWidth’, 2, ‘FontSize’, 20);
hold off;
Error in Design_Project1>@(FPsg)vsg0((Fsg0+FPsg)/Fsg0) (line 27)
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
Error in Design_Project1>@(FPsg)FPsg/vsg(FPsg) (line 33)
CPsg = @(FPsg) FPsg/vsg(FPsg);
Error in Design_Project1>@(FPsg,FA,FB,FP,FR)(-kapp*CA(FA,FB,FR,FP)*CB(FA,FB,FR,FP))-km(CP(FA,FB,FR,FP)-CPsg(FPsg)) (line 38)
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
Error in Design_Project1 (line 68)
dFP = dFPdV(FPsg, FA, FB, FP, FR);%% Design Project Part 2
% 2.1
% Constants:
kapp = 0.009; % m^3/mol*min
L = 1; % m
Vtot = 0.25; % m^3
FT0 = 20; % mol/ min
v0 = 0.08; % m^3/min
P = 100; % atm
rho = 4.2; % kg/m^3
mu = 0.492*10^-5; % kg/m*s
dp = 0.015; % m
phi = 0.75; % ?
km = 4; % 1/min
Fsg0 = 0.1; % mol/min
% Cases:
vsg0 = 0.1; % m^3/min
%vsg0 = 0.001; % m^3/min
v = @(FA, FB, FR, FP) ((v0/FT0)*(FA+FB+FR+FP));
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
CA = @(FA, FB, FR, FP) FA/v(FA, FB, FR, FP);
CB = @(FA, FB, FR, FP) FB/v(FA, FB, FR, FP);
CP = @(FA, FB, FR, FP) FP/v(FA, FB, FR, FP);
CR = @(FA, FB, FR, FP) FR/v(FA, FB, FR, FP);
CPsg = @(FPsg) FPsg/vsg(FPsg);
dFAdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFBdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFRdV = @(FA, FB, FR, FP) -kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
dFpsgdV = @(FPsg, FP) km(CP-CPsg);
FA = 10; % mol/ min
FB = 10; % mol/ min
FR = 0; % mol/ min
FP = 0; % mol/ min
FPsg = 0.1; % mol/min
dV = 0.01;
Vlim = 0.25;
Vspan = 0:dV:Vlim;
CA_values = zeros(size(Vspan));
CB_values = zeros(size(Vspan));
CP_values = zeros(size(Vspan));
CR_values = zeros(size(Vspan));
CPsg_values = zeros(size(Vspan));
FA_values = zeros(size(Vspan));
FB_values = zeros(size(Vspan));
FR_values = zeros(size(Vspan));
FP_values = zeros(size(Vspan));
FPsg_values = zeros(size(Vspan));
for i=1:length(Vspan)
dFA = dFAdV(FA, FB, FR, FP);
dFB = dFBdV(FA, FB, FR, FP);
dFR = dFRdV(FA, FB, FR, FP);
dFP = dFPdV(FPsg, FA, FB, FP, FR);
dFPsg = dFPsgdV(Fpsg, FP);
CA_values(i) = CA(FA, FB, FR, FP);
CB_values(i) = CB(FA, FB, FR, FP);
CP_values(i) = CP(FA, FB, FR, FP);
CR_values(i) = CR(FA, FB, FR, FP);
CPsg_values(i) = CPsg(Fpsg);
dFA = FA+dFA*dV;
dFB = FB+dFB*dV;
dFR = FR+dFR*dV;
dFP = FP+dFP*dV;
dFPsg = FPsg+dFPsg*dV;
FA_values(i) = FA;
FB_values(i) = FB;
FR_values(i) = FR;
FP_values(i) = FP;
FPsg_values(i) = FPsg;
end
figure()
hold on;
plot(Vspan, FA_values,’LineWidth’, 2);
plot(Vspan, FB_values,’LineWidth’, 2);
plot(Vspan, FP_values,’LineWidth’, 2);
plot(Vspan, FR_values,’LineWidth’, 2);
plot(Vspan, FPsg_values,’LineWidth’, 2);
xlabel(‘PBR volume V [=] m^3’);
ylabel(‘f(V) [=] mol/min’);
set(gca, ‘LineWidth’, 2, ‘FontSize’, 20);
hold off;
Error in Design_Project1>@(FPsg)vsg0((Fsg0+FPsg)/Fsg0) (line 27)
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
Error in Design_Project1>@(FPsg)FPsg/vsg(FPsg) (line 33)
CPsg = @(FPsg) FPsg/vsg(FPsg);
Error in Design_Project1>@(FPsg,FA,FB,FP,FR)(-kapp*CA(FA,FB,FR,FP)*CB(FA,FB,FR,FP))-km(CP(FA,FB,FR,FP)-CPsg(FPsg)) (line 38)
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
Error in Design_Project1 (line 68)
dFP = dFPdV(FPsg, FA, FB, FP, FR); %% Design Project Part 2
% 2.1
% Constants:
kapp = 0.009; % m^3/mol*min
L = 1; % m
Vtot = 0.25; % m^3
FT0 = 20; % mol/ min
v0 = 0.08; % m^3/min
P = 100; % atm
rho = 4.2; % kg/m^3
mu = 0.492*10^-5; % kg/m*s
dp = 0.015; % m
phi = 0.75; % ?
km = 4; % 1/min
Fsg0 = 0.1; % mol/min
% Cases:
vsg0 = 0.1; % m^3/min
%vsg0 = 0.001; % m^3/min
v = @(FA, FB, FR, FP) ((v0/FT0)*(FA+FB+FR+FP));
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
CA = @(FA, FB, FR, FP) FA/v(FA, FB, FR, FP);
CB = @(FA, FB, FR, FP) FB/v(FA, FB, FR, FP);
CP = @(FA, FB, FR, FP) FP/v(FA, FB, FR, FP);
CR = @(FA, FB, FR, FP) FR/v(FA, FB, FR, FP);
CPsg = @(FPsg) FPsg/vsg(FPsg);
dFAdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFBdV = @(FA, FB, FR, FP) kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFRdV = @(FA, FB, FR, FP) -kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP);
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
dFpsgdV = @(FPsg, FP) km(CP-CPsg);
FA = 10; % mol/ min
FB = 10; % mol/ min
FR = 0; % mol/ min
FP = 0; % mol/ min
FPsg = 0.1; % mol/min
dV = 0.01;
Vlim = 0.25;
Vspan = 0:dV:Vlim;
CA_values = zeros(size(Vspan));
CB_values = zeros(size(Vspan));
CP_values = zeros(size(Vspan));
CR_values = zeros(size(Vspan));
CPsg_values = zeros(size(Vspan));
FA_values = zeros(size(Vspan));
FB_values = zeros(size(Vspan));
FR_values = zeros(size(Vspan));
FP_values = zeros(size(Vspan));
FPsg_values = zeros(size(Vspan));
for i=1:length(Vspan)
dFA = dFAdV(FA, FB, FR, FP);
dFB = dFBdV(FA, FB, FR, FP);
dFR = dFRdV(FA, FB, FR, FP);
dFP = dFPdV(FPsg, FA, FB, FP, FR);
dFPsg = dFPsgdV(Fpsg, FP);
CA_values(i) = CA(FA, FB, FR, FP);
CB_values(i) = CB(FA, FB, FR, FP);
CP_values(i) = CP(FA, FB, FR, FP);
CR_values(i) = CR(FA, FB, FR, FP);
CPsg_values(i) = CPsg(Fpsg);
dFA = FA+dFA*dV;
dFB = FB+dFB*dV;
dFR = FR+dFR*dV;
dFP = FP+dFP*dV;
dFPsg = FPsg+dFPsg*dV;
FA_values(i) = FA;
FB_values(i) = FB;
FR_values(i) = FR;
FP_values(i) = FP;
FPsg_values(i) = FPsg;
end
figure()
hold on;
plot(Vspan, FA_values,’LineWidth’, 2);
plot(Vspan, FB_values,’LineWidth’, 2);
plot(Vspan, FP_values,’LineWidth’, 2);
plot(Vspan, FR_values,’LineWidth’, 2);
plot(Vspan, FPsg_values,’LineWidth’, 2);
xlabel(‘PBR volume V [=] m^3’);
ylabel(‘f(V) [=] mol/min’);
set(gca, ‘LineWidth’, 2, ‘FontSize’, 20);
hold off;
Error in Design_Project1>@(FPsg)vsg0((Fsg0+FPsg)/Fsg0) (line 27)
vsg = @(FPsg) vsg0((Fsg0+FPsg)/Fsg0);
Error in Design_Project1>@(FPsg)FPsg/vsg(FPsg) (line 33)
CPsg = @(FPsg) FPsg/vsg(FPsg);
Error in Design_Project1>@(FPsg,FA,FB,FP,FR)(-kapp*CA(FA,FB,FR,FP)*CB(FA,FB,FR,FP))-km(CP(FA,FB,FR,FP)-CPsg(FPsg)) (line 38)
dFPdV = @(FPsg, FA, FB, FP, FR) (-kapp*CA(FA, FB, FR, FP)*CB(FA, FB, FR, FP))-km(CP(FA, FB, FR, FP)-CPsg(FPsg));
Error in Design_Project1 (line 68)
dFP = dFPdV(FPsg, FA, FB, FP, FR); ode MATLAB Answers — New Questions
Error with matrix calculation
% matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3"% matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3" % matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3" matrix MATLAB Answers — New Questions
Simulink Discrete Filter Sample Time
Hello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
JanHello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
Jan Hello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
Jan #simulink, #fundamentals MATLAB Answers — New Questions
Ellipsoid Mask based on user input of dimension and euler angle
Actually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
endActually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
end Actually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
end image processing, mathematics, matrix array, optimization, binary MATLAB Answers — New Questions