Tag Archives: matlab
Why do I get an invalid Python executable path error when running the “pyenv” function?
Previously I was able to use the "pyenv" function in MATLAB with my Python environment. However, now when I try to use the "pyenv" function, I get the following error message. Why am I suddenly receiving this error?
Error using pyenv
‘<path>’ is not a path to a valid Python executable.Previously I was able to use the "pyenv" function in MATLAB with my Python environment. However, now when I try to use the "pyenv" function, I get the following error message. Why am I suddenly receiving this error?
Error using pyenv
‘<path>’ is not a path to a valid Python executable. Previously I was able to use the "pyenv" function in MATLAB with my Python environment. However, now when I try to use the "pyenv" function, I get the following error message. Why am I suddenly receiving this error?
Error using pyenv
‘<path>’ is not a path to a valid Python executable. python, pyenv MATLAB Answers — New Questions
Finding the closest coordinate from a surface plot based on a X, Y location
Hello, I want to extrapolate a point (longitude,latitude) from the coordinates of a surface file (attached here as "slab_strike") as it is empty (Strike=NaN) when using interp2 as the points are outside the boundary. Despsite I used the option "nearest" is empty anyway.
% Coordinates of the points:
lat_GMM= -17.8990;
lon_GMM=-73.5295;
% The surface plot
load slab_strike % Loading the slab strike
Slab_strike.x=x
Slab_strike.y=y
Slab_strike.z=z
Strike = interp2(Slab_strike.x,Slab_strike.y,Slab_strike.z,lon_GMM,lat_GMM)
As Strike=NaN, there is a way I can choose the closest point value from the surface instead.
I would appreciate the helpHello, I want to extrapolate a point (longitude,latitude) from the coordinates of a surface file (attached here as "slab_strike") as it is empty (Strike=NaN) when using interp2 as the points are outside the boundary. Despsite I used the option "nearest" is empty anyway.
% Coordinates of the points:
lat_GMM= -17.8990;
lon_GMM=-73.5295;
% The surface plot
load slab_strike % Loading the slab strike
Slab_strike.x=x
Slab_strike.y=y
Slab_strike.z=z
Strike = interp2(Slab_strike.x,Slab_strike.y,Slab_strike.z,lon_GMM,lat_GMM)
As Strike=NaN, there is a way I can choose the closest point value from the surface instead.
I would appreciate the help Hello, I want to extrapolate a point (longitude,latitude) from the coordinates of a surface file (attached here as "slab_strike") as it is empty (Strike=NaN) when using interp2 as the points are outside the boundary. Despsite I used the option "nearest" is empty anyway.
% Coordinates of the points:
lat_GMM= -17.8990;
lon_GMM=-73.5295;
% The surface plot
load slab_strike % Loading the slab strike
Slab_strike.x=x
Slab_strike.y=y
Slab_strike.z=z
Strike = interp2(Slab_strike.x,Slab_strike.y,Slab_strike.z,lon_GMM,lat_GMM)
As Strike=NaN, there is a way I can choose the closest point value from the surface instead.
I would appreciate the help selecting the closest point reference MATLAB Answers — New Questions
Issue connecting Simulink to Arduino Nano 33 IoT
I’m having an issue connecting my Arduino Nano 33 IoT to simulink. When I try to run it, I get the error message: "Unrecognized feild name " HostCOMPort" " I’m unsure how to resolve this and would greatly appricate the help!
The device shows up in my device manager and I can run code in Arduino IDE and Matlab without issues. Its only when I use Simulink is there a problem. Im using the cable that came in the Engineering Rev 2 kit from Arduino as well as a usb to usb-c converter to plug into my surface go to connect my computer to the Nano. I am able to run a regular Arduino Uno using the same setup through simiulink.
I’ve notcied that everytime I try to run the simulink program, the port in the device manager will change from "Arduino Nano 33 IoT" to the bootloader version. And also Matlab will tell me that an arduino device is detected again. My guess is that the Nano is restarting everytime or something? Im not really sure.I’m having an issue connecting my Arduino Nano 33 IoT to simulink. When I try to run it, I get the error message: "Unrecognized feild name " HostCOMPort" " I’m unsure how to resolve this and would greatly appricate the help!
The device shows up in my device manager and I can run code in Arduino IDE and Matlab without issues. Its only when I use Simulink is there a problem. Im using the cable that came in the Engineering Rev 2 kit from Arduino as well as a usb to usb-c converter to plug into my surface go to connect my computer to the Nano. I am able to run a regular Arduino Uno using the same setup through simiulink.
I’ve notcied that everytime I try to run the simulink program, the port in the device manager will change from "Arduino Nano 33 IoT" to the bootloader version. And also Matlab will tell me that an arduino device is detected again. My guess is that the Nano is restarting everytime or something? Im not really sure. I’m having an issue connecting my Arduino Nano 33 IoT to simulink. When I try to run it, I get the error message: "Unrecognized feild name " HostCOMPort" " I’m unsure how to resolve this and would greatly appricate the help!
The device shows up in my device manager and I can run code in Arduino IDE and Matlab without issues. Its only when I use Simulink is there a problem. Im using the cable that came in the Engineering Rev 2 kit from Arduino as well as a usb to usb-c converter to plug into my surface go to connect my computer to the Nano. I am able to run a regular Arduino Uno using the same setup through simiulink.
I’ve notcied that everytime I try to run the simulink program, the port in the device manager will change from "Arduino Nano 33 IoT" to the bootloader version. And also Matlab will tell me that an arduino device is detected again. My guess is that the Nano is restarting everytime or something? Im not really sure. simulink, arduino, nano MATLAB Answers — New Questions
How can I create an offset of a boundary?
How can I create an offset of a boundary?
rng(‘default’)
x = rand(30,1);
y = rand(30,1);
plot(x,y,’.’)
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
My desired output:How can I create an offset of a boundary?
rng(‘default’)
x = rand(30,1);
y = rand(30,1);
plot(x,y,’.’)
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
My desired output: How can I create an offset of a boundary?
rng(‘default’)
x = rand(30,1);
y = rand(30,1);
plot(x,y,’.’)
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
My desired output: offset, boundary MATLAB Answers — New Questions
How can I control the output data type of the “Signal Editor” block?
How can I control the output data type of the "Signal Editor" block?How can I control the output data type of the "Signal Editor" block? How can I control the output data type of the "Signal Editor" block? signal, editor, simulink, data, types, mat, file, output MATLAB Answers — New Questions
How i get a graph that i attached here with this matlab code?
function HTP()
clc
clear all format long % hybrid Carreau
% Define constants
J1 = 0.1;
J2 = 0.1;
J3 = 0.1;
J4 = 0.1;
JS = 0.1;
z = 0.1;
S = 0.1;
GC = 0.1;
Gr = 0.1;
H = 0.1;
a = 0.1;
m = 1;
G = 0.5;
phi = 0.1;
% Define time vector
t = linspace(0, 5, 100); % 100 points between 0 and 5
%t= 1;
% Calculate u1 and u2
u1 = exp(-t) – 1;
% Compute u2 with corrected parentheses and mathematical operations
exp_t = exp(t); % Compute exp(t) once for efficiency
term1 = -33 / J1 * (1 – exp_t – z / 3 * S);
term2 = 2 * GC * J3 + 2 * Gr * J2;
term3 = (2 * J4 * H * a^2) / (1 + m^2);
term4 = 3 * G * exp_t + 6 * exp_t / ((1 – phi)^2.5);
term5 = 2 * GC * JS * exp_t + 2 * Gr * J2 * exp_t;
u2 = (term1 + term2 – term3 – term4 – term5 + term3 * (exp_t – m + m * exp_t)) / (6 * a);
% Compute u
y = 1; % Define y as 1 or another constant value; adjust as needed
u = u1 * y + u2 * y.^2;
% Plot the result
phi = 0.1
figure ;
plot(t, u);
phi= 0.2
figure ;
plot(t, u);
phi = 0.3
figure ;
plot(t, u);
phi = 0.4
figure ;
plot(t, u);
xlabel(‘Time (t)’);
ylabel(‘u(t)’);
title(‘Plot of u(t)’);
axis([0 5 min(u) max(u)]);
grid on;
endfunction HTP()
clc
clear all format long % hybrid Carreau
% Define constants
J1 = 0.1;
J2 = 0.1;
J3 = 0.1;
J4 = 0.1;
JS = 0.1;
z = 0.1;
S = 0.1;
GC = 0.1;
Gr = 0.1;
H = 0.1;
a = 0.1;
m = 1;
G = 0.5;
phi = 0.1;
% Define time vector
t = linspace(0, 5, 100); % 100 points between 0 and 5
%t= 1;
% Calculate u1 and u2
u1 = exp(-t) – 1;
% Compute u2 with corrected parentheses and mathematical operations
exp_t = exp(t); % Compute exp(t) once for efficiency
term1 = -33 / J1 * (1 – exp_t – z / 3 * S);
term2 = 2 * GC * J3 + 2 * Gr * J2;
term3 = (2 * J4 * H * a^2) / (1 + m^2);
term4 = 3 * G * exp_t + 6 * exp_t / ((1 – phi)^2.5);
term5 = 2 * GC * JS * exp_t + 2 * Gr * J2 * exp_t;
u2 = (term1 + term2 – term3 – term4 – term5 + term3 * (exp_t – m + m * exp_t)) / (6 * a);
% Compute u
y = 1; % Define y as 1 or another constant value; adjust as needed
u = u1 * y + u2 * y.^2;
% Plot the result
phi = 0.1
figure ;
plot(t, u);
phi= 0.2
figure ;
plot(t, u);
phi = 0.3
figure ;
plot(t, u);
phi = 0.4
figure ;
plot(t, u);
xlabel(‘Time (t)’);
ylabel(‘u(t)’);
title(‘Plot of u(t)’);
axis([0 5 min(u) max(u)]);
grid on;
end function HTP()
clc
clear all format long % hybrid Carreau
% Define constants
J1 = 0.1;
J2 = 0.1;
J3 = 0.1;
J4 = 0.1;
JS = 0.1;
z = 0.1;
S = 0.1;
GC = 0.1;
Gr = 0.1;
H = 0.1;
a = 0.1;
m = 1;
G = 0.5;
phi = 0.1;
% Define time vector
t = linspace(0, 5, 100); % 100 points between 0 and 5
%t= 1;
% Calculate u1 and u2
u1 = exp(-t) – 1;
% Compute u2 with corrected parentheses and mathematical operations
exp_t = exp(t); % Compute exp(t) once for efficiency
term1 = -33 / J1 * (1 – exp_t – z / 3 * S);
term2 = 2 * GC * J3 + 2 * Gr * J2;
term3 = (2 * J4 * H * a^2) / (1 + m^2);
term4 = 3 * G * exp_t + 6 * exp_t / ((1 – phi)^2.5);
term5 = 2 * GC * JS * exp_t + 2 * Gr * J2 * exp_t;
u2 = (term1 + term2 – term3 – term4 – term5 + term3 * (exp_t – m + m * exp_t)) / (6 * a);
% Compute u
y = 1; % Define y as 1 or another constant value; adjust as needed
u = u1 * y + u2 * y.^2;
% Plot the result
phi = 0.1
figure ;
plot(t, u);
phi= 0.2
figure ;
plot(t, u);
phi = 0.3
figure ;
plot(t, u);
phi = 0.4
figure ;
plot(t, u);
xlabel(‘Time (t)’);
ylabel(‘u(t)’);
title(‘Plot of u(t)’);
axis([0 5 min(u) max(u)]);
grid on;
end multiple lines in one graph MATLAB Answers — New Questions
write a function called tri_area returns the area of a triangle with base b and height h
hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me
function [area] = tri_area([b,h]);
tri_area([b,h])=(0.5)*(b)*(h)
area=tri_area([b,h])
end
%command window
area = tri_area[3,2])hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me
function [area] = tri_area([b,h]);
tri_area([b,h])=(0.5)*(b)*(h)
area=tri_area([b,h])
end
%command window
area = tri_area[3,2]) hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me
function [area] = tri_area([b,h]);
tri_area([b,h])=(0.5)*(b)*(h)
area=tri_area([b,h])
end
%command window
area = tri_area[3,2]) matlab function, homework MATLAB Answers — New Questions
Copy-pasting variables (values) to edior in 2021b
Copy-pasting column vector values from workspace to editor used to automatically include ; and give me everything in a nicely formated single row. After updating to 2021b it results in a long list of values (each one in a separate row).
For example:
Create a column vector:
> A = [1; 2; 3; 4; 5];
Open it in the workspace, select entire column and copy (ctrl-c)
Paste in the editor results with:
1
2
3
4
5
while it used to result with:
1;2;3;4;5
Is there a way to switch back to the old behavior of copy-pasting variables?
I use it a lot, for example when saving the results in my scripts as starting values for the future and the new format makes the scripts much longer and messier.
Thank you very much in advance for any suggestions.Copy-pasting column vector values from workspace to editor used to automatically include ; and give me everything in a nicely formated single row. After updating to 2021b it results in a long list of values (each one in a separate row).
For example:
Create a column vector:
> A = [1; 2; 3; 4; 5];
Open it in the workspace, select entire column and copy (ctrl-c)
Paste in the editor results with:
1
2
3
4
5
while it used to result with:
1;2;3;4;5
Is there a way to switch back to the old behavior of copy-pasting variables?
I use it a lot, for example when saving the results in my scripts as starting values for the future and the new format makes the scripts much longer and messier.
Thank you very much in advance for any suggestions. Copy-pasting column vector values from workspace to editor used to automatically include ; and give me everything in a nicely formated single row. After updating to 2021b it results in a long list of values (each one in a separate row).
For example:
Create a column vector:
> A = [1; 2; 3; 4; 5];
Open it in the workspace, select entire column and copy (ctrl-c)
Paste in the editor results with:
1
2
3
4
5
while it used to result with:
1;2;3;4;5
Is there a way to switch back to the old behavior of copy-pasting variables?
I use it a lot, for example when saving the results in my scripts as starting values for the future and the new format makes the scripts much longer and messier.
Thank you very much in advance for any suggestions. copy-paste, editor, variables, 2021b update MATLAB Answers — New Questions
appdesigner tab view issue
Hi:
I have an app that showing the tab group at left, I noticed that when the tab name is too long, it will not be fully displayed. I tried to drag the corners of the tab but still not work, as shown in screen shot.
is there anyway to address this issue? i.e. to let the tab names fully shown.
Thanks!
YuHi:
I have an app that showing the tab group at left, I noticed that when the tab name is too long, it will not be fully displayed. I tried to drag the corners of the tab but still not work, as shown in screen shot.
is there anyway to address this issue? i.e. to let the tab names fully shown.
Thanks!
Yu Hi:
I have an app that showing the tab group at left, I noticed that when the tab name is too long, it will not be fully displayed. I tried to drag the corners of the tab but still not work, as shown in screen shot.
is there anyway to address this issue? i.e. to let the tab names fully shown.
Thanks!
Yu appdesigner tab view issue MATLAB Answers — New Questions
PNG Library Filed: Not a PNG File
Image Processing ToolBox, The function "imread" can not identify .png file. Why is this???Image Processing ToolBox, The function "imread" can not identify .png file. Why is this??? Image Processing ToolBox, The function "imread" can not identify .png file. Why is this??? image processing toolbox, imread MATLAB Answers — New Questions
How to solve diffusion equation by the crank – Nicolson method?
I have a diffusion equation 1D:
dC/dt =D*d2C/dx2
with D is changed with time.
Hepl me……
Thank you so much!I have a diffusion equation 1D:
dC/dt =D*d2C/dx2
with D is changed with time.
Hepl me……
Thank you so much! I have a diffusion equation 1D:
dC/dt =D*d2C/dx2
with D is changed with time.
Hepl me……
Thank you so much! MATLAB Answers — New Questions
Why is my model not converging with ode45 solver ?
I am trying to simulate an electronical device that can be modeled by a mass-spring-damper system with an additional non-linear force. The equation at the equilibrium for the system is the following :
The goal of my MATLAB code is to solve this equation for $x$ and find the equilibrium. For this purpose, I use the `ode45` function like this (all coefficient are defined in my code but not shown here) :
x0 = 0;
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
The equation is good according to my teachers and several papers but the solver never converges and I can’t see why. All coefficient are defined according to the dimensions of a capacitive micromachined ultrasound transducer. The solution of ode45 is the following :
This is obviously wrong because the dimensions of a cmut are bellow millimeter.
Can you see any mistakes in the way I use the ode45 solver ?
Full code :
% DIMENSIONS DE LA MEMBRANE
e = 500e-9; % epaisseur [m]
r = 20e-6; % rayon [m]
d0 = 550e-9; % epaisseur de cavite [m]
a = pi * r^2; % surface de la membrane [m^2]
% PARAMETRES MECANIQUES
E = 200e9; % module d’Young du SiN [Pa]
nu = 0.25; % coefficient de poisson du SiN
eta = 18.5e-6; % viscosité dynamique de l’air [Pa.s]
p0 = 1e5; % pression exterieure [Pa]
rhoSiN = 3170; % densite du SiN [Kg/m^3]
m = rhoSiN * a * e; % masse membrane [Kg]
K = (16 * E * e^3) / (3 * (1 – nu^2) * r^2); % raideur [N/m]
B = (eta * pi * r^2) / e; % amortissement [N.s/m]
% PARAMETRES ELECTRIQUES
eps0 = 8.85e-12; % permittivité diélectrique du vide [F/m]
V0 = 10; % tension de polarisation [V]
% Conditions initiales et plage de temps
x0 = 0;
ti = 0; tf = 1e-3;
dt = 1e-6;
tspan = linspace(ti, tf, 1/dt);
% Résolution par RK4
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
plot(t,x,’-‘)
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
References :
– Y. Wang, L. -M. He, Z. Li, W. Xu and J. Ren, "A computationally efficient nonlinear dynamic model for cMUT based on COMSOL and MATLAB/Simulink"
– T. Merrien, A. Boulmé and D. Certon, "Lumped-Parameter Equivalent Circuit Modeling of CMUT Array Elements"
I tried several solver from MATLAB and implemented my own Runge-Kutta algorithm based on the Wikipedia example. I also verified the coefficients according to my references.I am trying to simulate an electronical device that can be modeled by a mass-spring-damper system with an additional non-linear force. The equation at the equilibrium for the system is the following :
The goal of my MATLAB code is to solve this equation for $x$ and find the equilibrium. For this purpose, I use the `ode45` function like this (all coefficient are defined in my code but not shown here) :
x0 = 0;
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
The equation is good according to my teachers and several papers but the solver never converges and I can’t see why. All coefficient are defined according to the dimensions of a capacitive micromachined ultrasound transducer. The solution of ode45 is the following :
This is obviously wrong because the dimensions of a cmut are bellow millimeter.
Can you see any mistakes in the way I use the ode45 solver ?
Full code :
% DIMENSIONS DE LA MEMBRANE
e = 500e-9; % epaisseur [m]
r = 20e-6; % rayon [m]
d0 = 550e-9; % epaisseur de cavite [m]
a = pi * r^2; % surface de la membrane [m^2]
% PARAMETRES MECANIQUES
E = 200e9; % module d’Young du SiN [Pa]
nu = 0.25; % coefficient de poisson du SiN
eta = 18.5e-6; % viscosité dynamique de l’air [Pa.s]
p0 = 1e5; % pression exterieure [Pa]
rhoSiN = 3170; % densite du SiN [Kg/m^3]
m = rhoSiN * a * e; % masse membrane [Kg]
K = (16 * E * e^3) / (3 * (1 – nu^2) * r^2); % raideur [N/m]
B = (eta * pi * r^2) / e; % amortissement [N.s/m]
% PARAMETRES ELECTRIQUES
eps0 = 8.85e-12; % permittivité diélectrique du vide [F/m]
V0 = 10; % tension de polarisation [V]
% Conditions initiales et plage de temps
x0 = 0;
ti = 0; tf = 1e-3;
dt = 1e-6;
tspan = linspace(ti, tf, 1/dt);
% Résolution par RK4
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
plot(t,x,’-‘)
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
References :
– Y. Wang, L. -M. He, Z. Li, W. Xu and J. Ren, "A computationally efficient nonlinear dynamic model for cMUT based on COMSOL and MATLAB/Simulink"
– T. Merrien, A. Boulmé and D. Certon, "Lumped-Parameter Equivalent Circuit Modeling of CMUT Array Elements"
I tried several solver from MATLAB and implemented my own Runge-Kutta algorithm based on the Wikipedia example. I also verified the coefficients according to my references. I am trying to simulate an electronical device that can be modeled by a mass-spring-damper system with an additional non-linear force. The equation at the equilibrium for the system is the following :
The goal of my MATLAB code is to solve this equation for $x$ and find the equilibrium. For this purpose, I use the `ode45` function like this (all coefficient are defined in my code but not shown here) :
x0 = 0;
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
The equation is good according to my teachers and several papers but the solver never converges and I can’t see why. All coefficient are defined according to the dimensions of a capacitive micromachined ultrasound transducer. The solution of ode45 is the following :
This is obviously wrong because the dimensions of a cmut are bellow millimeter.
Can you see any mistakes in the way I use the ode45 solver ?
Full code :
% DIMENSIONS DE LA MEMBRANE
e = 500e-9; % epaisseur [m]
r = 20e-6; % rayon [m]
d0 = 550e-9; % epaisseur de cavite [m]
a = pi * r^2; % surface de la membrane [m^2]
% PARAMETRES MECANIQUES
E = 200e9; % module d’Young du SiN [Pa]
nu = 0.25; % coefficient de poisson du SiN
eta = 18.5e-6; % viscosité dynamique de l’air [Pa.s]
p0 = 1e5; % pression exterieure [Pa]
rhoSiN = 3170; % densite du SiN [Kg/m^3]
m = rhoSiN * a * e; % masse membrane [Kg]
K = (16 * E * e^3) / (3 * (1 – nu^2) * r^2); % raideur [N/m]
B = (eta * pi * r^2) / e; % amortissement [N.s/m]
% PARAMETRES ELECTRIQUES
eps0 = 8.85e-12; % permittivité diélectrique du vide [F/m]
V0 = 10; % tension de polarisation [V]
% Conditions initiales et plage de temps
x0 = 0;
ti = 0; tf = 1e-3;
dt = 1e-6;
tspan = linspace(ti, tf, 1/dt);
% Résolution par RK4
[t, x] = ode45(@(t, x) odefun(t, x, eps0, a, V0, B, d0, K), tspan, x0);
plot(t,x,’-‘)
function dxdt = odefun(t, x, eps, a, V, B, d0, K)
dxdt = ((eps * a * V^2) ./ (2 * B * (d0 – x).^2)) + ((K / B) .* x);
end
References :
– Y. Wang, L. -M. He, Z. Li, W. Xu and J. Ren, "A computationally efficient nonlinear dynamic model for cMUT based on COMSOL and MATLAB/Simulink"
– T. Merrien, A. Boulmé and D. Certon, "Lumped-Parameter Equivalent Circuit Modeling of CMUT Array Elements"
I tried several solver from MATLAB and implemented my own Runge-Kutta algorithm based on the Wikipedia example. I also verified the coefficients according to my references. differential equations, physics, matlab, model, ode45, ode MATLAB Answers — New Questions
How to correctly abort a running Matlab function/thread in a .NET Assembly in .NET8?
Dear MathWorks team
In our .NET Framework 4.7.2 application we instanciate a class from a Matlab .NET assembly and call one function to calculate.
The call is done in a own background thread of the application.
If the calculation takes too long or the calculation request has been canceled, we just aborted the .NET thread with thread.Abort().
.NET core (at least v8) does not support the Abort() function anymore. The only general alternative suggestion I could find is to outsource the call into an own process and then kill the process if required. This seems to be quite complicated and Matlab takes a few seconds to initialize on the first call, which is too slow for us.
Is there any best practice / example how to achieve this?
Thanks in advance
Public Sub New(ByVal theTimeout As Integer, theData As Object, theWorkerMethod As TheWorkerDelegate, theCompleteCallback As CompleteCallbackDelegate, theSynchObj As ISynchronizeInvoke)
_theData = theData
_theCompleteCallback = theCompleteCallback
_theWorkerMethod = theWorkerMethod
_theSyncObject = theSynchObj
If theTimeout > 0 Then
_timeoutTimer = New WcsTimer(theTimeout * 1000, WcsTimer.TimerMode.SingleShot)
AddHandler _timeoutTimer.TimeElapsed, AddressOf _timeoutTimerElapsed
End If
_theThread = New Threading.Thread(AddressOf _startWorkerThread)
_theThread.Name = "Matlab Supervision Thread"
_theThread.Start()
End Sub
Public Sub Abort()
_stopTimeoutTimer()
If _theThread IsNot Nothing AndAlso _theThread.IsAlive Then
_theThread.Abort()
End If
_theThread = Nothing
End Sub
Private Sub _startWorkerThread()
Dim theEx As Exception = Nothing
Try
_theWorkerMethod(_theData) -> Matlab call
Catch ex As Exception
theEx = ex
End Try
_stopTimeoutTimer()
Dim p As Object() = {_theData, False, theEx}
_theSyncObject.Invoke(_theCompleteCallback, p)
End Sub
Private Sub _timeoutTimerElapsed(sender As Object, e As EventArgs)
WcsTrace.Log(WcsTrace.Category.Detailed, $"********* BackgroupWorker Timeoute -> Abort **************")
Abort()
_theCompleteCallback(_theData, True, Nothing)
End SubDear MathWorks team
In our .NET Framework 4.7.2 application we instanciate a class from a Matlab .NET assembly and call one function to calculate.
The call is done in a own background thread of the application.
If the calculation takes too long or the calculation request has been canceled, we just aborted the .NET thread with thread.Abort().
.NET core (at least v8) does not support the Abort() function anymore. The only general alternative suggestion I could find is to outsource the call into an own process and then kill the process if required. This seems to be quite complicated and Matlab takes a few seconds to initialize on the first call, which is too slow for us.
Is there any best practice / example how to achieve this?
Thanks in advance
Public Sub New(ByVal theTimeout As Integer, theData As Object, theWorkerMethod As TheWorkerDelegate, theCompleteCallback As CompleteCallbackDelegate, theSynchObj As ISynchronizeInvoke)
_theData = theData
_theCompleteCallback = theCompleteCallback
_theWorkerMethod = theWorkerMethod
_theSyncObject = theSynchObj
If theTimeout > 0 Then
_timeoutTimer = New WcsTimer(theTimeout * 1000, WcsTimer.TimerMode.SingleShot)
AddHandler _timeoutTimer.TimeElapsed, AddressOf _timeoutTimerElapsed
End If
_theThread = New Threading.Thread(AddressOf _startWorkerThread)
_theThread.Name = "Matlab Supervision Thread"
_theThread.Start()
End Sub
Public Sub Abort()
_stopTimeoutTimer()
If _theThread IsNot Nothing AndAlso _theThread.IsAlive Then
_theThread.Abort()
End If
_theThread = Nothing
End Sub
Private Sub _startWorkerThread()
Dim theEx As Exception = Nothing
Try
_theWorkerMethod(_theData) -> Matlab call
Catch ex As Exception
theEx = ex
End Try
_stopTimeoutTimer()
Dim p As Object() = {_theData, False, theEx}
_theSyncObject.Invoke(_theCompleteCallback, p)
End Sub
Private Sub _timeoutTimerElapsed(sender As Object, e As EventArgs)
WcsTrace.Log(WcsTrace.Category.Detailed, $"********* BackgroupWorker Timeoute -> Abort **************")
Abort()
_theCompleteCallback(_theData, True, Nothing)
End Sub Dear MathWorks team
In our .NET Framework 4.7.2 application we instanciate a class from a Matlab .NET assembly and call one function to calculate.
The call is done in a own background thread of the application.
If the calculation takes too long or the calculation request has been canceled, we just aborted the .NET thread with thread.Abort().
.NET core (at least v8) does not support the Abort() function anymore. The only general alternative suggestion I could find is to outsource the call into an own process and then kill the process if required. This seems to be quite complicated and Matlab takes a few seconds to initialize on the first call, which is too slow for us.
Is there any best practice / example how to achieve this?
Thanks in advance
Public Sub New(ByVal theTimeout As Integer, theData As Object, theWorkerMethod As TheWorkerDelegate, theCompleteCallback As CompleteCallbackDelegate, theSynchObj As ISynchronizeInvoke)
_theData = theData
_theCompleteCallback = theCompleteCallback
_theWorkerMethod = theWorkerMethod
_theSyncObject = theSynchObj
If theTimeout > 0 Then
_timeoutTimer = New WcsTimer(theTimeout * 1000, WcsTimer.TimerMode.SingleShot)
AddHandler _timeoutTimer.TimeElapsed, AddressOf _timeoutTimerElapsed
End If
_theThread = New Threading.Thread(AddressOf _startWorkerThread)
_theThread.Name = "Matlab Supervision Thread"
_theThread.Start()
End Sub
Public Sub Abort()
_stopTimeoutTimer()
If _theThread IsNot Nothing AndAlso _theThread.IsAlive Then
_theThread.Abort()
End If
_theThread = Nothing
End Sub
Private Sub _startWorkerThread()
Dim theEx As Exception = Nothing
Try
_theWorkerMethod(_theData) -> Matlab call
Catch ex As Exception
theEx = ex
End Try
_stopTimeoutTimer()
Dim p As Object() = {_theData, False, theEx}
_theSyncObject.Invoke(_theCompleteCallback, p)
End Sub
Private Sub _timeoutTimerElapsed(sender As Object, e As EventArgs)
WcsTrace.Log(WcsTrace.Category.Detailed, $"********* BackgroupWorker Timeoute -> Abort **************")
Abort()
_theCompleteCallback(_theData, True, Nothing)
End Sub .net8, thread, abort MATLAB Answers — New Questions
HDL Coder; Matlab Function Blocks and Clocked Processes
I belive my request is quite straigth forward.
I want the logic of my Matlab Funciton Block to be generated as clocked logic and not combinatorial logic.
Lets use the eml_hdl_incrementer example.
It generates
eml_inc_blk_1_output : PROCESS (ctr_preset, ctr_preset_val_unsigned, current_count)
But I would want it to generate
eml_inc_blk_1_output : PROCESS (clk)
I mean it should not be a miracle to achieve, but I could not find an option, that allows me to enforce this behaviour.
Is there an option to make matlab generate a clocked process or do I have to use specific patterns in my funciton?I belive my request is quite straigth forward.
I want the logic of my Matlab Funciton Block to be generated as clocked logic and not combinatorial logic.
Lets use the eml_hdl_incrementer example.
It generates
eml_inc_blk_1_output : PROCESS (ctr_preset, ctr_preset_val_unsigned, current_count)
But I would want it to generate
eml_inc_blk_1_output : PROCESS (clk)
I mean it should not be a miracle to achieve, but I could not find an option, that allows me to enforce this behaviour.
Is there an option to make matlab generate a clocked process or do I have to use specific patterns in my funciton? I belive my request is quite straigth forward.
I want the logic of my Matlab Funciton Block to be generated as clocked logic and not combinatorial logic.
Lets use the eml_hdl_incrementer example.
It generates
eml_inc_blk_1_output : PROCESS (ctr_preset, ctr_preset_val_unsigned, current_count)
But I would want it to generate
eml_inc_blk_1_output : PROCESS (clk)
I mean it should not be a miracle to achieve, but I could not find an option, that allows me to enforce this behaviour.
Is there an option to make matlab generate a clocked process or do I have to use specific patterns in my funciton? hdl coder, clocked process MATLAB Answers — New Questions
how to plot from .csv file?
i hv to find percentage difference values for columns 3,6,9,12 for 2 pol HH and VV separatelyand find out difference at each frequency
later at x axis frequency and y axis these indivdual percentage values has to be plotted in bar chart
A=csvread(‘baseline.csv’,1,0)
freq=A(1:6,2);
A_1_PE_HH=A(1:6,3);
B_2_PE_HH=A(1:6,9);
A_1_fre_HH=A(1:6,6);
B_2_fre_HH=A(1:6,12);
HH_1st_example=((A_1_PE_HH(2,1)-B_2_PE_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 6 columns
HH_2nd_example=((A_1_PE_HH(2,1)-B_2_fre_HH(2,1))A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 12 columns
HH_3rd_example=((A_1_fre_HH(2,1)-B_2_PE_HH(2,1))/A_1_fre_HH(2,1))*100 %finding percentage differnce between 6 and 9 columns
HH_4th_example=((A_1_fre_HH(2,1)-B_2_fre_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 6 and 12 columns
same i have to find for VV also i m getting stuck at this placei hv to find percentage difference values for columns 3,6,9,12 for 2 pol HH and VV separatelyand find out difference at each frequency
later at x axis frequency and y axis these indivdual percentage values has to be plotted in bar chart
A=csvread(‘baseline.csv’,1,0)
freq=A(1:6,2);
A_1_PE_HH=A(1:6,3);
B_2_PE_HH=A(1:6,9);
A_1_fre_HH=A(1:6,6);
B_2_fre_HH=A(1:6,12);
HH_1st_example=((A_1_PE_HH(2,1)-B_2_PE_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 6 columns
HH_2nd_example=((A_1_PE_HH(2,1)-B_2_fre_HH(2,1))A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 12 columns
HH_3rd_example=((A_1_fre_HH(2,1)-B_2_PE_HH(2,1))/A_1_fre_HH(2,1))*100 %finding percentage differnce between 6 and 9 columns
HH_4th_example=((A_1_fre_HH(2,1)-B_2_fre_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 6 and 12 columns
same i have to find for VV also i m getting stuck at this place i hv to find percentage difference values for columns 3,6,9,12 for 2 pol HH and VV separatelyand find out difference at each frequency
later at x axis frequency and y axis these indivdual percentage values has to be plotted in bar chart
A=csvread(‘baseline.csv’,1,0)
freq=A(1:6,2);
A_1_PE_HH=A(1:6,3);
B_2_PE_HH=A(1:6,9);
A_1_fre_HH=A(1:6,6);
B_2_fre_HH=A(1:6,12);
HH_1st_example=((A_1_PE_HH(2,1)-B_2_PE_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 6 columns
HH_2nd_example=((A_1_PE_HH(2,1)-B_2_fre_HH(2,1))A_1_PE_HH(2,1))*100 %finding percentage differnce between 3 and 12 columns
HH_3rd_example=((A_1_fre_HH(2,1)-B_2_PE_HH(2,1))/A_1_fre_HH(2,1))*100 %finding percentage differnce between 6 and 9 columns
HH_4th_example=((A_1_fre_HH(2,1)-B_2_fre_HH(2,1))/A_1_PE_HH(2,1))*100 %finding percentage differnce between 6 and 12 columns
same i have to find for VV also i m getting stuck at this place plot MATLAB Answers — New Questions
Transforming Optimization Code from Problem-Based to Solver-Based Approach in MATLAB
Hello,
I have successfully implemented an ILP problem using MATLAB’s problem-based optimization approach. However, I am now looking to switch to the solver-based approach to take advantage of its flexibility and efficiency.
In the problem-based approach, I defined binary decision variables, constraints, and an objective function using optimvar, optimconstr, and optimexpr. The code works well, but I need guidance on how to transform this code into a solver-based format using intlinprog.
Here’s a summary of what I have:
Decision Variables:
A 3D binary matrix A(N, numNodes, num_vehicles) for task assignment.
A binary vector chi(num_vehicles) for satisfaction.
Other binary variables like z, t_wait_aux, etc.
Constraints:
Assignment constraints, dependency constraints, and time-based constraints.
I linearized expressions using auxiliary variables and max constraints.
Objective Function:
The objective is to maximize the satisfaction rate, expressed as a linear function of chi.
Could you provide guidance or directions how to systematically convert my existing problem-based variables and constraints into the matrix form required by intlinprog
Here is the code
the problem is attached.
Thank you for your continued help!Hello,
I have successfully implemented an ILP problem using MATLAB’s problem-based optimization approach. However, I am now looking to switch to the solver-based approach to take advantage of its flexibility and efficiency.
In the problem-based approach, I defined binary decision variables, constraints, and an objective function using optimvar, optimconstr, and optimexpr. The code works well, but I need guidance on how to transform this code into a solver-based format using intlinprog.
Here’s a summary of what I have:
Decision Variables:
A 3D binary matrix A(N, numNodes, num_vehicles) for task assignment.
A binary vector chi(num_vehicles) for satisfaction.
Other binary variables like z, t_wait_aux, etc.
Constraints:
Assignment constraints, dependency constraints, and time-based constraints.
I linearized expressions using auxiliary variables and max constraints.
Objective Function:
The objective is to maximize the satisfaction rate, expressed as a linear function of chi.
Could you provide guidance or directions how to systematically convert my existing problem-based variables and constraints into the matrix form required by intlinprog
Here is the code
the problem is attached.
Thank you for your continued help! Hello,
I have successfully implemented an ILP problem using MATLAB’s problem-based optimization approach. However, I am now looking to switch to the solver-based approach to take advantage of its flexibility and efficiency.
In the problem-based approach, I defined binary decision variables, constraints, and an objective function using optimvar, optimconstr, and optimexpr. The code works well, but I need guidance on how to transform this code into a solver-based format using intlinprog.
Here’s a summary of what I have:
Decision Variables:
A 3D binary matrix A(N, numNodes, num_vehicles) for task assignment.
A binary vector chi(num_vehicles) for satisfaction.
Other binary variables like z, t_wait_aux, etc.
Constraints:
Assignment constraints, dependency constraints, and time-based constraints.
I linearized expressions using auxiliary variables and max constraints.
Objective Function:
The objective is to maximize the satisfaction rate, expressed as a linear function of chi.
Could you provide guidance or directions how to systematically convert my existing problem-based variables and constraints into the matrix form required by intlinprog
Here is the code
the problem is attached.
Thank you for your continued help! solver based optimization, ilp, matlab code MATLAB Answers — New Questions
resize netcdf resolution to smaller size
Hi, I hope I can explain correctly.
I have data of size 649x337x268.
is it possible to resize it to 109x57x268?Hi, I hope I can explain correctly.
I have data of size 649x337x268.
is it possible to resize it to 109x57x268? Hi, I hope I can explain correctly.
I have data of size 649x337x268.
is it possible to resize it to 109x57x268? resize, resolution, nc file MATLAB Answers — New Questions
2D unsteady heat advection diffusion equation with Crank-Nicolson method scheme
how can i solve a 2D unsteady heat advection diffusion equation with Crank-Nicolson method scheme using Matlab? the convective flows are given by Taylor-Green vortex solution.how can i solve a 2D unsteady heat advection diffusion equation with Crank-Nicolson method scheme using Matlab? the convective flows are given by Taylor-Green vortex solution. how can i solve a 2D unsteady heat advection diffusion equation with Crank-Nicolson method scheme using Matlab? the convective flows are given by Taylor-Green vortex solution. crank-nicolson MATLAB Answers — New Questions
Simulink model -Code generation
Hello
I am currently trying to generate C++ code from a Simulink model (code only for grt.tlc system target file). The model includes some s-functions in which the mdlstart() functions are waiting for outside signal (TCP connexion).
I can’t send those signal during code generation. However, the code generation phases includes build and initialization steps. So then, initialization triggers mdlstart functions in s-function blocks.
Is there a way to avoid this intialization step during code generation (options in configuration parameters window)?
Thank youHello
I am currently trying to generate C++ code from a Simulink model (code only for grt.tlc system target file). The model includes some s-functions in which the mdlstart() functions are waiting for outside signal (TCP connexion).
I can’t send those signal during code generation. However, the code generation phases includes build and initialization steps. So then, initialization triggers mdlstart functions in s-function blocks.
Is there a way to avoid this intialization step during code generation (options in configuration parameters window)?
Thank you Hello
I am currently trying to generate C++ code from a Simulink model (code only for grt.tlc system target file). The model includes some s-functions in which the mdlstart() functions are waiting for outside signal (TCP connexion).
I can’t send those signal during code generation. However, the code generation phases includes build and initialization steps. So then, initialization triggers mdlstart functions in s-function blocks.
Is there a way to avoid this intialization step during code generation (options in configuration parameters window)?
Thank you simulink, code generation, s-function MATLAB Answers — New Questions
load mex library error on Linux
Hi,
I getting this error while trying to load a mex library on Ubuntu 20.04
>> loadlibrary(‘ice’, @iceproto)
Error using message/getString
In ‘MATLAB:loadlibrary:ErrorRunningFromCommandLine’, parameter {0} must be a real scalar.
Error in loadlibrary
I have build a mex, proto and thunk files
ice.mexa64 iceproto.m icethunk.so
Cheers,
JoseHi,
I getting this error while trying to load a mex library on Ubuntu 20.04
>> loadlibrary(‘ice’, @iceproto)
Error using message/getString
In ‘MATLAB:loadlibrary:ErrorRunningFromCommandLine’, parameter {0} must be a real scalar.
Error in loadlibrary
I have build a mex, proto and thunk files
ice.mexa64 iceproto.m icethunk.so
Cheers,
Jose Hi,
I getting this error while trying to load a mex library on Ubuntu 20.04
>> loadlibrary(‘ice’, @iceproto)
Error using message/getString
In ‘MATLAB:loadlibrary:ErrorRunningFromCommandLine’, parameter {0} must be a real scalar.
Error in loadlibrary
I have build a mex, proto and thunk files
ice.mexa64 iceproto.m icethunk.so
Cheers,
Jose mex MATLAB Answers — New Questions