Category: Matlab
Category Archives: Matlab
Helical trajectory generation using frenet frame
How to generate a helical trajectory using frenet frame?
Position vector given as
[x y z]^T=[[500sin(0.01t) 500cos(0.01t) −2t−20000]^T
initial position is
ζ (0) = [−300 0 −19800]^T
initial line velocity is
υ(0) =[5 0 0]^T,
the initial attitude is
γ (0) = [0, 0, 0]^T
How to convert this data to frenet frame and find attitude coordinates and then plot a helical trajectoryHow to generate a helical trajectory using frenet frame?
Position vector given as
[x y z]^T=[[500sin(0.01t) 500cos(0.01t) −2t−20000]^T
initial position is
ζ (0) = [−300 0 −19800]^T
initial line velocity is
υ(0) =[5 0 0]^T,
the initial attitude is
γ (0) = [0, 0, 0]^T
How to convert this data to frenet frame and find attitude coordinates and then plot a helical trajectory How to generate a helical trajectory using frenet frame?
Position vector given as
[x y z]^T=[[500sin(0.01t) 500cos(0.01t) −2t−20000]^T
initial position is
ζ (0) = [−300 0 −19800]^T
initial line velocity is
υ(0) =[5 0 0]^T,
the initial attitude is
γ (0) = [0, 0, 0]^T
How to convert this data to frenet frame and find attitude coordinates and then plot a helical trajectory frenet, matlab, program, trajectory, helical, helix MATLAB Answers — New Questions
I was trying to play video in integrate HTML of App designer, but it is not working correctly on App. It does work in browsers.
Here is my code for HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件选择器</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.chosefile {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 50px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.calc {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 200px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.chosefile:hover, .calc:hover {
background-color: #0056b3;
}
.chosefile:active, .calc:hover {
transform: scale(0.98);
}
</style>
<style>
#frameMarker {
width: 100px;
height: 10px;
background-color: red;
position: absolute;
}
#coordinateArea {
width: 100%;
height: 20px;
position: relative;
background-color: #ddd;
}
</style>
</head>
<body>
<input type="file" id="fileInput" style="display: none;" />
<button class="chosefile" onclick="setup()">选择文件</button>
<button class="calc" onclick="setup();">选择</button>
<div id="prompt">
<span><label for="prompt"><strong>Data from MATLAB will display here:</strong></label></span>
<br/><br/>
<div id ="dataDisplay">Please set data in MATLAB…</div>
</div>
<video id="videoPlayer" width="320" height="240" controls>
<source src="E:/OneDrive/BDF/test.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
<div id="coordinateArea">
<div id="frameMarker"></div>
</div>
</body>
<script type="text/javascript">
function setup(htmlComponent) {
let button1 = document.querySelector(".calc");
let button2 = document.querySelector(".chosefile")
button1.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ButtonClicked",1);
});
button2.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ChosefileClicked",1);
});
htmlComponent.addEventListener("DataChanged", function(event) {
document.getElementById("dataDisplay").innerHTML = htmlComponent.Data;
});
}
</script>
<script>
document.getElementById(‘videoPlayer’).addEventListener(‘timeupdate’, function() {
var video = document.getElementById(‘videoPlayer’);
var marker = document.getElementById(‘frameMarker’);
var duration = video.duration;
var currentTime = video.currentTime;
var coordinateAreaWidth = document.getElementById(‘coordinateArea’).clientWidth;
// 计算标记的位置
var position = (currentTime / duration) * coordinateAreaWidth;
marker.style.left = position + ‘px’;
});
</script>
</html>Here is my code for HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件选择器</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.chosefile {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 50px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.calc {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 200px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.chosefile:hover, .calc:hover {
background-color: #0056b3;
}
.chosefile:active, .calc:hover {
transform: scale(0.98);
}
</style>
<style>
#frameMarker {
width: 100px;
height: 10px;
background-color: red;
position: absolute;
}
#coordinateArea {
width: 100%;
height: 20px;
position: relative;
background-color: #ddd;
}
</style>
</head>
<body>
<input type="file" id="fileInput" style="display: none;" />
<button class="chosefile" onclick="setup()">选择文件</button>
<button class="calc" onclick="setup();">选择</button>
<div id="prompt">
<span><label for="prompt"><strong>Data from MATLAB will display here:</strong></label></span>
<br/><br/>
<div id ="dataDisplay">Please set data in MATLAB…</div>
</div>
<video id="videoPlayer" width="320" height="240" controls>
<source src="E:/OneDrive/BDF/test.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
<div id="coordinateArea">
<div id="frameMarker"></div>
</div>
</body>
<script type="text/javascript">
function setup(htmlComponent) {
let button1 = document.querySelector(".calc");
let button2 = document.querySelector(".chosefile")
button1.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ButtonClicked",1);
});
button2.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ChosefileClicked",1);
});
htmlComponent.addEventListener("DataChanged", function(event) {
document.getElementById("dataDisplay").innerHTML = htmlComponent.Data;
});
}
</script>
<script>
document.getElementById(‘videoPlayer’).addEventListener(‘timeupdate’, function() {
var video = document.getElementById(‘videoPlayer’);
var marker = document.getElementById(‘frameMarker’);
var duration = video.duration;
var currentTime = video.currentTime;
var coordinateAreaWidth = document.getElementById(‘coordinateArea’).clientWidth;
// 计算标记的位置
var position = (currentTime / duration) * coordinateAreaWidth;
marker.style.left = position + ‘px’;
});
</script>
</html> Here is my code for HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件选择器</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.chosefile {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 50px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.calc {
position: absolute;
top: 50px; /* 距顶部50像素 */
left: 200px; /* 距左侧50像素 */
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s, transform 0.2s;
}
.chosefile:hover, .calc:hover {
background-color: #0056b3;
}
.chosefile:active, .calc:hover {
transform: scale(0.98);
}
</style>
<style>
#frameMarker {
width: 100px;
height: 10px;
background-color: red;
position: absolute;
}
#coordinateArea {
width: 100%;
height: 20px;
position: relative;
background-color: #ddd;
}
</style>
</head>
<body>
<input type="file" id="fileInput" style="display: none;" />
<button class="chosefile" onclick="setup()">选择文件</button>
<button class="calc" onclick="setup();">选择</button>
<div id="prompt">
<span><label for="prompt"><strong>Data from MATLAB will display here:</strong></label></span>
<br/><br/>
<div id ="dataDisplay">Please set data in MATLAB…</div>
</div>
<video id="videoPlayer" width="320" height="240" controls>
<source src="E:/OneDrive/BDF/test.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
<div id="coordinateArea">
<div id="frameMarker"></div>
</div>
</body>
<script type="text/javascript">
function setup(htmlComponent) {
let button1 = document.querySelector(".calc");
let button2 = document.querySelector(".chosefile")
button1.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ButtonClicked",1);
});
button2.addEventListener("click", function(event) {
htmlComponent.sendEventToMATLAB("ChosefileClicked",1);
});
htmlComponent.addEventListener("DataChanged", function(event) {
document.getElementById("dataDisplay").innerHTML = htmlComponent.Data;
});
}
</script>
<script>
document.getElementById(‘videoPlayer’).addEventListener(‘timeupdate’, function() {
var video = document.getElementById(‘videoPlayer’);
var marker = document.getElementById(‘frameMarker’);
var duration = video.duration;
var currentTime = video.currentTime;
var coordinateAreaWidth = document.getElementById(‘coordinateArea’).clientWidth;
// 计算标记的位置
var position = (currentTime / duration) * coordinateAreaWidth;
marker.style.left = position + ‘px’;
});
</script>
</html> appdesigner, app designer MATLAB Answers — New Questions
I have written a code to reproduce fig 2 in the attached paper but I don’t seem to get it right.
I am trying a code to reproduce fig 2 in the attached paper, but I don’t seem to get it right. Any help would be apreciated. Thanks
% Material properties
rho = 1.35e3; % Density in kg/m^3
Cp = @(T) (-0.07827 + 0.00223*T – 8.66702e-7*T.^2 + 9.63112e-11*T.^3) * 1e3; % Specific heat in J/g°C converted to J/kgK
alpha = 3.5e3; % Absorption coefficient in m^-1
R = 0.1; % Reflectivity
pulseWidth = 6e-9; % Pulse width in seconds
fluence = 790e-3; % Laser fluence in J/cm^2
I0 = fluence / pulseWidth; % Peak laser intensity
% Spatial domain
L = 1e-3; % Length of the sample in meters (1 mm)
num_elements = 100; % Number of spatial elements
x = linspace(0, L, num_elements); % Spatial grid
% Time domain
total_time = 50e-9; % Total time in seconds
num_time_steps = 500; % Number of time steps
t = linspace(0, total_time, num_time_steps); % Time vector
% Initial temperature distribution
T0 = 20; % Initial temperature in °C
T = T0 * ones(num_elements, 1); % Initial temperature vector
% Thermal diffusivity (D = k / (rho * Cp))
D = 0.4e-4; % Thermal diffusivity in m^2/s
k = D * rho * Cp(T0); % Thermal conductivity in W/m°C
% FEM setup
dx = L / (num_elements – 1); % Spatial step size
dt = total_time / num_time_steps; % Time step size
% FEM matrices
A = zeros(num_elements, num_elements);
B = zeros(num_elements, 1);
% Assembly of FEM matrices
for i = 2:num_elements-1
A(i, i-1) = k / dx^2;
A(i, i) = -2 * k / dx^2;
A(i, i+1) = k / dx^2;
end
% Boundary conditions
A(1, 1) = 1;
A(1, 2) = 0;
A(end, end) = 1;
A(end, end-1) = 0;
% Time-stepping solution
T_history = zeros(num_elements, num_time_steps);
T_history(:, 1) = T;
for n = 1:num_time_steps-1
B(2:end-1) = alpha * I0 * exp(-alpha * x(2:end-1)) * (1 – R);
B(end) = T0; % Bottom boundary condition (fixed temperature)
T = T + dt * (A * T + B);
T(1) = T0; % surface boundary condition
T_history(:, n+1) = T;
end
% Plotting the results
figure;
hold on;
plot(t, T_history(1, :), ‘r’, ‘DisplayName’, ‘Surface’);
plot(t, T_history(find(x >= 1e-6, 1), :), ‘g’, ‘DisplayName’, ‘1 mum’);
plot(t, T_history(find(x >= 5e-6, 1), :), ‘b’, ‘DisplayName’, ‘5 mum’);
xlabel(‘Time (s)’);
ylabel(‘Temperature (°C)’);
legend;
title(‘Temperature profiles at different depths’);
hold off;I am trying a code to reproduce fig 2 in the attached paper, but I don’t seem to get it right. Any help would be apreciated. Thanks
% Material properties
rho = 1.35e3; % Density in kg/m^3
Cp = @(T) (-0.07827 + 0.00223*T – 8.66702e-7*T.^2 + 9.63112e-11*T.^3) * 1e3; % Specific heat in J/g°C converted to J/kgK
alpha = 3.5e3; % Absorption coefficient in m^-1
R = 0.1; % Reflectivity
pulseWidth = 6e-9; % Pulse width in seconds
fluence = 790e-3; % Laser fluence in J/cm^2
I0 = fluence / pulseWidth; % Peak laser intensity
% Spatial domain
L = 1e-3; % Length of the sample in meters (1 mm)
num_elements = 100; % Number of spatial elements
x = linspace(0, L, num_elements); % Spatial grid
% Time domain
total_time = 50e-9; % Total time in seconds
num_time_steps = 500; % Number of time steps
t = linspace(0, total_time, num_time_steps); % Time vector
% Initial temperature distribution
T0 = 20; % Initial temperature in °C
T = T0 * ones(num_elements, 1); % Initial temperature vector
% Thermal diffusivity (D = k / (rho * Cp))
D = 0.4e-4; % Thermal diffusivity in m^2/s
k = D * rho * Cp(T0); % Thermal conductivity in W/m°C
% FEM setup
dx = L / (num_elements – 1); % Spatial step size
dt = total_time / num_time_steps; % Time step size
% FEM matrices
A = zeros(num_elements, num_elements);
B = zeros(num_elements, 1);
% Assembly of FEM matrices
for i = 2:num_elements-1
A(i, i-1) = k / dx^2;
A(i, i) = -2 * k / dx^2;
A(i, i+1) = k / dx^2;
end
% Boundary conditions
A(1, 1) = 1;
A(1, 2) = 0;
A(end, end) = 1;
A(end, end-1) = 0;
% Time-stepping solution
T_history = zeros(num_elements, num_time_steps);
T_history(:, 1) = T;
for n = 1:num_time_steps-1
B(2:end-1) = alpha * I0 * exp(-alpha * x(2:end-1)) * (1 – R);
B(end) = T0; % Bottom boundary condition (fixed temperature)
T = T + dt * (A * T + B);
T(1) = T0; % surface boundary condition
T_history(:, n+1) = T;
end
% Plotting the results
figure;
hold on;
plot(t, T_history(1, :), ‘r’, ‘DisplayName’, ‘Surface’);
plot(t, T_history(find(x >= 1e-6, 1), :), ‘g’, ‘DisplayName’, ‘1 mum’);
plot(t, T_history(find(x >= 5e-6, 1), :), ‘b’, ‘DisplayName’, ‘5 mum’);
xlabel(‘Time (s)’);
ylabel(‘Temperature (°C)’);
legend;
title(‘Temperature profiles at different depths’);
hold off; I am trying a code to reproduce fig 2 in the attached paper, but I don’t seem to get it right. Any help would be apreciated. Thanks
% Material properties
rho = 1.35e3; % Density in kg/m^3
Cp = @(T) (-0.07827 + 0.00223*T – 8.66702e-7*T.^2 + 9.63112e-11*T.^3) * 1e3; % Specific heat in J/g°C converted to J/kgK
alpha = 3.5e3; % Absorption coefficient in m^-1
R = 0.1; % Reflectivity
pulseWidth = 6e-9; % Pulse width in seconds
fluence = 790e-3; % Laser fluence in J/cm^2
I0 = fluence / pulseWidth; % Peak laser intensity
% Spatial domain
L = 1e-3; % Length of the sample in meters (1 mm)
num_elements = 100; % Number of spatial elements
x = linspace(0, L, num_elements); % Spatial grid
% Time domain
total_time = 50e-9; % Total time in seconds
num_time_steps = 500; % Number of time steps
t = linspace(0, total_time, num_time_steps); % Time vector
% Initial temperature distribution
T0 = 20; % Initial temperature in °C
T = T0 * ones(num_elements, 1); % Initial temperature vector
% Thermal diffusivity (D = k / (rho * Cp))
D = 0.4e-4; % Thermal diffusivity in m^2/s
k = D * rho * Cp(T0); % Thermal conductivity in W/m°C
% FEM setup
dx = L / (num_elements – 1); % Spatial step size
dt = total_time / num_time_steps; % Time step size
% FEM matrices
A = zeros(num_elements, num_elements);
B = zeros(num_elements, 1);
% Assembly of FEM matrices
for i = 2:num_elements-1
A(i, i-1) = k / dx^2;
A(i, i) = -2 * k / dx^2;
A(i, i+1) = k / dx^2;
end
% Boundary conditions
A(1, 1) = 1;
A(1, 2) = 0;
A(end, end) = 1;
A(end, end-1) = 0;
% Time-stepping solution
T_history = zeros(num_elements, num_time_steps);
T_history(:, 1) = T;
for n = 1:num_time_steps-1
B(2:end-1) = alpha * I0 * exp(-alpha * x(2:end-1)) * (1 – R);
B(end) = T0; % Bottom boundary condition (fixed temperature)
T = T + dt * (A * T + B);
T(1) = T0; % surface boundary condition
T_history(:, n+1) = T;
end
% Plotting the results
figure;
hold on;
plot(t, T_history(1, :), ‘r’, ‘DisplayName’, ‘Surface’);
plot(t, T_history(find(x >= 1e-6, 1), :), ‘g’, ‘DisplayName’, ‘1 mum’);
plot(t, T_history(find(x >= 5e-6, 1), :), ‘b’, ‘DisplayName’, ‘5 mum’);
xlabel(‘Time (s)’);
ylabel(‘Temperature (°C)’);
legend;
title(‘Temperature profiles at different depths’);
hold off; finite element method MATLAB Answers — New Questions
Visualozing Attention for Sequence Data in the Frequency domain
I have trouble finding out how i can map my attention weights onto my input data.
My input data is in a 512*1 Cell, it represents a vibration in the frequency-domain, after going through different layers (mainly 2 CNN and 2 Bi-GRU), i have a high level representation of it(480*1), that enters a self attention layer.
I am able to extract the attention weights (256*1), but I am unsure on how to map them to my input sequence, am i able to just upscale the attention vector and overlay it onto my input?
I’ve added a screenshots of the model structure, to help you understand the problem.
The whole problem is further illustrated in this research paper.
I would be grateful for anyone, who can help me understand how I need to proceed.I have trouble finding out how i can map my attention weights onto my input data.
My input data is in a 512*1 Cell, it represents a vibration in the frequency-domain, after going through different layers (mainly 2 CNN and 2 Bi-GRU), i have a high level representation of it(480*1), that enters a self attention layer.
I am able to extract the attention weights (256*1), but I am unsure on how to map them to my input sequence, am i able to just upscale the attention vector and overlay it onto my input?
I’ve added a screenshots of the model structure, to help you understand the problem.
The whole problem is further illustrated in this research paper.
I would be grateful for anyone, who can help me understand how I need to proceed. I have trouble finding out how i can map my attention weights onto my input data.
My input data is in a 512*1 Cell, it represents a vibration in the frequency-domain, after going through different layers (mainly 2 CNN and 2 Bi-GRU), i have a high level representation of it(480*1), that enters a self attention layer.
I am able to extract the attention weights (256*1), but I am unsure on how to map them to my input sequence, am i able to just upscale the attention vector and overlay it onto my input?
I’ve added a screenshots of the model structure, to help you understand the problem.
The whole problem is further illustrated in this research paper.
I would be grateful for anyone, who can help me understand how I need to proceed. machine learning, time series MATLAB Answers — New Questions
WindowButtonDownFcn vs zoom or pan
In my figure I have some little images; I’ve implemented WindowButtonDownFcn so when I click on an image, I do something different according to the image selected
The cursor position is checked with WindowButtonMotionFcn
Practically, every little image simulates a button with its callback function. I do this because the graphical aspect of my figure is better, and I can have a ‘button’ of different shape instead of the square or rectangular button shape. Moreover, I don’t have the button outline.
Im my figure I have also an axis, used to plot data.
When I activate the zoom or the panning, the WindowButtonDownFcn function doesn’t work, my ‘buttons’ don’t work anymore until I deactivate the zoom or the pan.
This behaviour there is also if I set the zoom (or panning) on programmatically.
Is there a way to avoid this behaviour? I need the WindowButtonDownFcn ALWAYS working.
Thank youIn my figure I have some little images; I’ve implemented WindowButtonDownFcn so when I click on an image, I do something different according to the image selected
The cursor position is checked with WindowButtonMotionFcn
Practically, every little image simulates a button with its callback function. I do this because the graphical aspect of my figure is better, and I can have a ‘button’ of different shape instead of the square or rectangular button shape. Moreover, I don’t have the button outline.
Im my figure I have also an axis, used to plot data.
When I activate the zoom or the panning, the WindowButtonDownFcn function doesn’t work, my ‘buttons’ don’t work anymore until I deactivate the zoom or the pan.
This behaviour there is also if I set the zoom (or panning) on programmatically.
Is there a way to avoid this behaviour? I need the WindowButtonDownFcn ALWAYS working.
Thank you In my figure I have some little images; I’ve implemented WindowButtonDownFcn so when I click on an image, I do something different according to the image selected
The cursor position is checked with WindowButtonMotionFcn
Practically, every little image simulates a button with its callback function. I do this because the graphical aspect of my figure is better, and I can have a ‘button’ of different shape instead of the square or rectangular button shape. Moreover, I don’t have the button outline.
Im my figure I have also an axis, used to plot data.
When I activate the zoom or the panning, the WindowButtonDownFcn function doesn’t work, my ‘buttons’ don’t work anymore until I deactivate the zoom or the pan.
This behaviour there is also if I set the zoom (or panning) on programmatically.
Is there a way to avoid this behaviour? I need the WindowButtonDownFcn ALWAYS working.
Thank you windowbuttondownfcn MATLAB Answers — New Questions
How to buy MATLAB license in Ukraine (2023)?
Dear Sirs,
I would like to buy MATLAB for the company in Ukraine.
But I can’t do that because Mathworks representer in Ukraine is russia.
Could you please help me to buy license officially?
Best wishes,
OlegDear Sirs,
I would like to buy MATLAB for the company in Ukraine.
But I can’t do that because Mathworks representer in Ukraine is russia.
Could you please help me to buy license officially?
Best wishes,
Oleg Dear Sirs,
I would like to buy MATLAB for the company in Ukraine.
But I can’t do that because Mathworks representer in Ukraine is russia.
Could you please help me to buy license officially?
Best wishes,
Oleg license purchase issue MATLAB Answers — New Questions
How to make the colorbar/colormap with colors the same as ANSYS in Matlab?
In ANSYS, when there is zero deflection, the color is blue. For maximum negative and maximum positive, red is shown. In matlab, when there is zero deflection, the color is green. For maximum positive deflection the color is red and for maximum negative deflection the color is blue. How to configure Matlab to display the same colorbar as Ansys?
See the difference between the figures:
Matlab:
Ansys:
Thank you!In ANSYS, when there is zero deflection, the color is blue. For maximum negative and maximum positive, red is shown. In matlab, when there is zero deflection, the color is green. For maximum positive deflection the color is red and for maximum negative deflection the color is blue. How to configure Matlab to display the same colorbar as Ansys?
See the difference between the figures:
Matlab:
Ansys:
Thank you! In ANSYS, when there is zero deflection, the color is blue. For maximum negative and maximum positive, red is shown. In matlab, when there is zero deflection, the color is green. For maximum positive deflection the color is red and for maximum negative deflection the color is blue. How to configure Matlab to display the same colorbar as Ansys?
See the difference between the figures:
Matlab:
Ansys:
Thank you! colormap, color, surface, contour, 3d plots, plot MATLAB Answers — New Questions
Error while importing Google Satellite image into Roadrunner
I have exported a Google Satellite image from QGIS (as a GeoTIFF file), however, when I try to import it into Roadrunner, the bounding box appears but the image doesn’t, and an error (visible in the attached image) appears in the output. How to solve this?I have exported a Google Satellite image from QGIS (as a GeoTIFF file), however, when I try to import it into Roadrunner, the bounding box appears but the image doesn’t, and an error (visible in the attached image) appears in the output. How to solve this? I have exported a Google Satellite image from QGIS (as a GeoTIFF file), however, when I try to import it into Roadrunner, the bounding box appears but the image doesn’t, and an error (visible in the attached image) appears in the output. How to solve this? google satellite, import MATLAB Answers — New Questions
How to make map with unequal colorbar
Hello everyone,
I know this question has been asked numeroud times, but still I am stuck at this.
I want to make a create a map in which colorbar is cutomized. I am pasting a example
Any help or tips will be great.
ThanksHello everyone,
I know this question has been asked numeroud times, but still I am stuck at this.
I want to make a create a map in which colorbar is cutomized. I am pasting a example
Any help or tips will be great.
Thanks Hello everyone,
I know this question has been asked numeroud times, but still I am stuck at this.
I want to make a create a map in which colorbar is cutomized. I am pasting a example
Any help or tips will be great.
Thanks colormap, colorbar MATLAB Answers — New Questions
S-Function cannot find a file (.exe) but it is clearly in the Matlab path
Hello,
I am working with a third party software (CarSim 2021) that is using a controller provided by a supplier as a black box. I have added Directory1 and its sub-folders to the Matlab path. The error message is (some names modified):
Error reported by S-function ‘Sfun_GenericSM_blahblah’ in ‘Directory1/Directory2/Directory3/Controller/ESP Controller Interface/ESP8’:
===> !!! Error GetLastError(2): File anExecutable.exe does not exist !!!
I can navigate to the .exe file and run it in my working directory within Directory1. I copied "anExecutable.exe" in additional locations within the Directory1 and Directory2 to address any potential path issue. I do see Sfun_GenericSM_blahblah.mexw64 in the path (as mentioned in https://www.mathworks.com/matlabcentral/answers/735042-s-function-does-not-exist-but-is-clearly-in-the-matlab-path).
I know this model ran on a different machine in the past; but, not sure about the Matlab version. I used both Matlab 2017b and 2023b. I get the same error.
I do not have access to the source code and the block SFunction parameters does not explicitly refer to the .exe file when I open the block parameters dialouge box.
Is there a way to point the model to the file (.exe) that it cannot find?
Thanks for the help!Hello,
I am working with a third party software (CarSim 2021) that is using a controller provided by a supplier as a black box. I have added Directory1 and its sub-folders to the Matlab path. The error message is (some names modified):
Error reported by S-function ‘Sfun_GenericSM_blahblah’ in ‘Directory1/Directory2/Directory3/Controller/ESP Controller Interface/ESP8’:
===> !!! Error GetLastError(2): File anExecutable.exe does not exist !!!
I can navigate to the .exe file and run it in my working directory within Directory1. I copied "anExecutable.exe" in additional locations within the Directory1 and Directory2 to address any potential path issue. I do see Sfun_GenericSM_blahblah.mexw64 in the path (as mentioned in https://www.mathworks.com/matlabcentral/answers/735042-s-function-does-not-exist-but-is-clearly-in-the-matlab-path).
I know this model ran on a different machine in the past; but, not sure about the Matlab version. I used both Matlab 2017b and 2023b. I get the same error.
I do not have access to the source code and the block SFunction parameters does not explicitly refer to the .exe file when I open the block parameters dialouge box.
Is there a way to point the model to the file (.exe) that it cannot find?
Thanks for the help! Hello,
I am working with a third party software (CarSim 2021) that is using a controller provided by a supplier as a black box. I have added Directory1 and its sub-folders to the Matlab path. The error message is (some names modified):
Error reported by S-function ‘Sfun_GenericSM_blahblah’ in ‘Directory1/Directory2/Directory3/Controller/ESP Controller Interface/ESP8’:
===> !!! Error GetLastError(2): File anExecutable.exe does not exist !!!
I can navigate to the .exe file and run it in my working directory within Directory1. I copied "anExecutable.exe" in additional locations within the Directory1 and Directory2 to address any potential path issue. I do see Sfun_GenericSM_blahblah.mexw64 in the path (as mentioned in https://www.mathworks.com/matlabcentral/answers/735042-s-function-does-not-exist-but-is-clearly-in-the-matlab-path).
I know this model ran on a different machine in the past; but, not sure about the Matlab version. I used both Matlab 2017b and 2023b. I get the same error.
I do not have access to the source code and the block SFunction parameters does not explicitly refer to the .exe file when I open the block parameters dialouge box.
Is there a way to point the model to the file (.exe) that it cannot find?
Thanks for the help! sfunction, finding external file, path problem MATLAB Answers — New Questions
Best way to buffer vector data in Simulink for processing over a time window
I’m working with a lidar-equipped robot, and every 0.2 seconds it provides an array of 360 values corresponding to the return intensity received at each angle. For my application, I need to do some statistical analysis on the data over a user-defined time-window. For offline processing in MATLAB, I’ve just been appending each new array of scan values to a matrix, so that I have a 360-column "Intensities" matrix which grows over time, and I can select the time-window for processing by selecting the appropriate rows from the matrix.
intensitiesMatrix(i,:) = new_scandata_array;
Now I’m trying to transition my code to Simulink (particularly because I want to use Stateflow for certain aspects of my application) and I want to do the same kind of data buffering so I can perform windowed processing on the data in real-time. For some reason I’m having a hard time figuring out the best way to collect my successive scan vectors into a form that I can then process, as I did in my regular MATLAB approach. I’ve looked a bit at Data Stores; is that the right approach? Or is there a good way to do this with matrices as I was doing in MATLAB?I’m working with a lidar-equipped robot, and every 0.2 seconds it provides an array of 360 values corresponding to the return intensity received at each angle. For my application, I need to do some statistical analysis on the data over a user-defined time-window. For offline processing in MATLAB, I’ve just been appending each new array of scan values to a matrix, so that I have a 360-column "Intensities" matrix which grows over time, and I can select the time-window for processing by selecting the appropriate rows from the matrix.
intensitiesMatrix(i,:) = new_scandata_array;
Now I’m trying to transition my code to Simulink (particularly because I want to use Stateflow for certain aspects of my application) and I want to do the same kind of data buffering so I can perform windowed processing on the data in real-time. For some reason I’m having a hard time figuring out the best way to collect my successive scan vectors into a form that I can then process, as I did in my regular MATLAB approach. I’ve looked a bit at Data Stores; is that the right approach? Or is there a good way to do this with matrices as I was doing in MATLAB? I’m working with a lidar-equipped robot, and every 0.2 seconds it provides an array of 360 values corresponding to the return intensity received at each angle. For my application, I need to do some statistical analysis on the data over a user-defined time-window. For offline processing in MATLAB, I’ve just been appending each new array of scan values to a matrix, so that I have a 360-column "Intensities" matrix which grows over time, and I can select the time-window for processing by selecting the appropriate rows from the matrix.
intensitiesMatrix(i,:) = new_scandata_array;
Now I’m trying to transition my code to Simulink (particularly because I want to use Stateflow for certain aspects of my application) and I want to do the same kind of data buffering so I can perform windowed processing on the data in real-time. For some reason I’m having a hard time figuring out the best way to collect my successive scan vectors into a form that I can then process, as I did in my regular MATLAB approach. I’ve looked a bit at Data Stores; is that the right approach? Or is there a good way to do this with matrices as I was doing in MATLAB? simulink data processing MATLAB Answers — New Questions
MATLAB to CPP code
In MATLAB, it is quite convenient to implement reading binary files with data types that are not several-integer-number of bytes, like
data = fread(fid, fsize, ‘bit12’);
I feel extremely frustrated about how to correctly convert this expression to C++ code?In MATLAB, it is quite convenient to implement reading binary files with data types that are not several-integer-number of bytes, like
data = fread(fid, fsize, ‘bit12’);
I feel extremely frustrated about how to correctly convert this expression to C++ code? In MATLAB, it is quite convenient to implement reading binary files with data types that are not several-integer-number of bytes, like
data = fread(fid, fsize, ‘bit12’);
I feel extremely frustrated about how to correctly convert this expression to C++ code? matlab and cpp MATLAB Answers — New Questions
Plot legend with 2-d layout
Is it possible to do four (or more) plots using hold on and then create a legend that has a 2-d layout like this?Is it possible to do four (or more) plots using hold on and then create a legend that has a 2-d layout like this? Is it possible to do four (or more) plots using hold on and then create a legend that has a 2-d layout like this? plot, legend MATLAB Answers — New Questions
Request for Simulink to provide link to offending block for “the model, ‘xxxx’, was changed after the SimState was saved”
This request refers to the three questions:
https://uk.mathworks.com/matlabcentral/answers/1736580-cannot-find-state-n-in-the-given-variable-error-when-trying-to-start-a-simulation-using-previous?s_tid=prof_contriblnk
https://uk.mathworks.com/matlabcentral/answers/182251-simulink-cannot-load-the-initial-simstate?s_tid=srchtitle
https://uk.mathworks.com/matlabcentral/answers/38166-simstate-error?s_tid=srchtitle
In all these examples, users (including me) are struggling because we are trying to use the "Save Operating Point" method.
The "Save Operating Point" method is extremely powerful, and a very useful feature of Simulink that we would like to exploit to its fullest extent.
However, as users find, it is extremely easy to encounter the following error, when trying to run the simulation using the "Saved Operating Point":
"Simulink cannot load the initial SimState because the model, ‘xxxx’, was changed after the SimState was saved. Run the simulation again and resave the SimState.
This is problematic when the model is very large, as the search space (number of subsystems and parameters) is huge. Finding the problem block/parameter is like looking for a needle in a haystack.
Often everything is PERFECT, except for perhaps one single parameterised block that is causing the issue. For the user to find this, without a hint from Simulink about where to start looking, is very difficult.
Simulink must KNOW where the new model is different to that in the saved states, because it is detecting that place and throwing the error.
Please could Simulink then tell the user WHICH block/parameter the problem is with?
Even just the FIRST block/parameter problem would be a help, because often there may be only one.
A link could be provided to the relevant block/parameter, or even just the text listing the block pathname.
Ideally a list of the problem blocks/parameters could be provided, if there are more than one.
Please can this be included in future Simulink versions?This request refers to the three questions:
https://uk.mathworks.com/matlabcentral/answers/1736580-cannot-find-state-n-in-the-given-variable-error-when-trying-to-start-a-simulation-using-previous?s_tid=prof_contriblnk
https://uk.mathworks.com/matlabcentral/answers/182251-simulink-cannot-load-the-initial-simstate?s_tid=srchtitle
https://uk.mathworks.com/matlabcentral/answers/38166-simstate-error?s_tid=srchtitle
In all these examples, users (including me) are struggling because we are trying to use the "Save Operating Point" method.
The "Save Operating Point" method is extremely powerful, and a very useful feature of Simulink that we would like to exploit to its fullest extent.
However, as users find, it is extremely easy to encounter the following error, when trying to run the simulation using the "Saved Operating Point":
"Simulink cannot load the initial SimState because the model, ‘xxxx’, was changed after the SimState was saved. Run the simulation again and resave the SimState.
This is problematic when the model is very large, as the search space (number of subsystems and parameters) is huge. Finding the problem block/parameter is like looking for a needle in a haystack.
Often everything is PERFECT, except for perhaps one single parameterised block that is causing the issue. For the user to find this, without a hint from Simulink about where to start looking, is very difficult.
Simulink must KNOW where the new model is different to that in the saved states, because it is detecting that place and throwing the error.
Please could Simulink then tell the user WHICH block/parameter the problem is with?
Even just the FIRST block/parameter problem would be a help, because often there may be only one.
A link could be provided to the relevant block/parameter, or even just the text listing the block pathname.
Ideally a list of the problem blocks/parameters could be provided, if there are more than one.
Please can this be included in future Simulink versions? This request refers to the three questions:
https://uk.mathworks.com/matlabcentral/answers/1736580-cannot-find-state-n-in-the-given-variable-error-when-trying-to-start-a-simulation-using-previous?s_tid=prof_contriblnk
https://uk.mathworks.com/matlabcentral/answers/182251-simulink-cannot-load-the-initial-simstate?s_tid=srchtitle
https://uk.mathworks.com/matlabcentral/answers/38166-simstate-error?s_tid=srchtitle
In all these examples, users (including me) are struggling because we are trying to use the "Save Operating Point" method.
The "Save Operating Point" method is extremely powerful, and a very useful feature of Simulink that we would like to exploit to its fullest extent.
However, as users find, it is extremely easy to encounter the following error, when trying to run the simulation using the "Saved Operating Point":
"Simulink cannot load the initial SimState because the model, ‘xxxx’, was changed after the SimState was saved. Run the simulation again and resave the SimState.
This is problematic when the model is very large, as the search space (number of subsystems and parameters) is huge. Finding the problem block/parameter is like looking for a needle in a haystack.
Often everything is PERFECT, except for perhaps one single parameterised block that is causing the issue. For the user to find this, without a hint from Simulink about where to start looking, is very difficult.
Simulink must KNOW where the new model is different to that in the saved states, because it is detecting that place and throwing the error.
Please could Simulink then tell the user WHICH block/parameter the problem is with?
Even just the FIRST block/parameter problem would be a help, because often there may be only one.
A link could be provided to the relevant block/parameter, or even just the text listing the block pathname.
Ideally a list of the problem blocks/parameters could be provided, if there are more than one.
Please can this be included in future Simulink versions? operating point, initial simstate MATLAB Answers — New Questions
Compute the basin of attraction for a steady state of an ordinary differential equation ODE
I need write a function called "compute_basin" that takes in a steady state and its k value and computes which set of initial conditions in [15,30] approach that steady state. Specifically it will return two values, "a" and "b", which describe the set [a,b] of initial conditions that approach the steady state. The function will be assessed by running
[a,b]=compute_basin(steady_state,k);
for many different values of k and the associated steady states.
Inputs:
a scalar value of a steady state
a scalar value of k (note the steady state should be correct for the k value)
Outputs:
a scalar for the lower bounds of the basin of attraction
a scalar for the upper bounds for the basin of attraction
This is what i have so far:
function [a, b] = compute_basin(Ceq, k)
% Initialize variables
a = 15; % Lower bound for the basin of attraction
b = 30; % Upper bound for the basin of attraction
threshold = 0.001; % Error threshold
% Binary search for the lower bound (a)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
right = mid;
else
left = mid + 0.1;
end
end
a = left;
% Binary search for the upper bound (b)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
left = mid;
else
right = mid – 0.1;
end
end
b = right;
end
But unfortunalty this is not correct. I have a tip saying that "There are many ways of doing this but a binary search algorithm might be helpful (Wikipedia entry for binary searchLinks to an external site.). Make sure that the [a,b] bounds are within the range of [15,30]. Note that some steady states may be unstable and so their basin of attraction will only be their exact value. In these cases a=b. It helps to solve for the upper and lower bounds separately, i.e. running the code for a and then running it again for b."
I have acces to three functions, the first is "compute_ode" that computes the derivative dC/dt for the differential equation model dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k.
function dcdt = compute_ode(t,c,k)
% write the equation for the differential equation and assign it to output dcdt
dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k;
end
Then i have the second "compute_states" that takes as input a value for k and then returns as output all real-valued steady states for the differential equation.
function vectCeq = compute_states(k)
% Coefficients of the polynomial equation -0.1*c^3 + 6.9*c^2 – 157.8*c + 1196 + k = 0
coeffs = [-0.1, 6.9, -157.8, 1196 + k];
% Find all roots of the polynomial
all_roots = roots(coeffs);
% Filter out complex roots
real_roots = all_roots(imag(all_roots) == 0);
% Return the real-valued steady states
vectCeq = real_roots;
end
And latsly, I have "compute_time_to_steady" that solves the differential equation and returns the earliest time it takes to get within 1% error of the steady state value:
function tstar = compute_time_to_steady(init_cond, k, steady_state)
% Set the options for the ODE solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-9);
% Define the ODE function as a nested function
function dcdt = ode_function(t, c)
dcdt = compute_ode(t, c, k);
end
% Initialize variables
tspan = [0 100000]; % Time range from 0 to 100,000
threshold = 0.001; % 1% error threshold
% Solve the ODE
[T, C] = ode45(@ode_function, tspan, init_cond, options);
% Iterate over the solution to find the first time it meets the criterion
for i = 1:length(T)
if abs(C(i) – steady_state) / steady_state < threshold
tstar = T(i);
return;
end
end
% If the criterion is not met within the time range, return the last time point
tstar = T(end);
end
function dcdt = compute_ode(t, c, k)
dcdt = 0.1 * (c – 20) * (23 – c) * (c – 26) + k;
end
function steady_states = compute_states(k)
% Define the steady state values based on the value of k
steady_states = [20; 23; 26];
end
I would really appriciate any help on computing the basin of attraction for a steady state!
Thank you!I need write a function called "compute_basin" that takes in a steady state and its k value and computes which set of initial conditions in [15,30] approach that steady state. Specifically it will return two values, "a" and "b", which describe the set [a,b] of initial conditions that approach the steady state. The function will be assessed by running
[a,b]=compute_basin(steady_state,k);
for many different values of k and the associated steady states.
Inputs:
a scalar value of a steady state
a scalar value of k (note the steady state should be correct for the k value)
Outputs:
a scalar for the lower bounds of the basin of attraction
a scalar for the upper bounds for the basin of attraction
This is what i have so far:
function [a, b] = compute_basin(Ceq, k)
% Initialize variables
a = 15; % Lower bound for the basin of attraction
b = 30; % Upper bound for the basin of attraction
threshold = 0.001; % Error threshold
% Binary search for the lower bound (a)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
right = mid;
else
left = mid + 0.1;
end
end
a = left;
% Binary search for the upper bound (b)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
left = mid;
else
right = mid – 0.1;
end
end
b = right;
end
But unfortunalty this is not correct. I have a tip saying that "There are many ways of doing this but a binary search algorithm might be helpful (Wikipedia entry for binary searchLinks to an external site.). Make sure that the [a,b] bounds are within the range of [15,30]. Note that some steady states may be unstable and so their basin of attraction will only be their exact value. In these cases a=b. It helps to solve for the upper and lower bounds separately, i.e. running the code for a and then running it again for b."
I have acces to three functions, the first is "compute_ode" that computes the derivative dC/dt for the differential equation model dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k.
function dcdt = compute_ode(t,c,k)
% write the equation for the differential equation and assign it to output dcdt
dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k;
end
Then i have the second "compute_states" that takes as input a value for k and then returns as output all real-valued steady states for the differential equation.
function vectCeq = compute_states(k)
% Coefficients of the polynomial equation -0.1*c^3 + 6.9*c^2 – 157.8*c + 1196 + k = 0
coeffs = [-0.1, 6.9, -157.8, 1196 + k];
% Find all roots of the polynomial
all_roots = roots(coeffs);
% Filter out complex roots
real_roots = all_roots(imag(all_roots) == 0);
% Return the real-valued steady states
vectCeq = real_roots;
end
And latsly, I have "compute_time_to_steady" that solves the differential equation and returns the earliest time it takes to get within 1% error of the steady state value:
function tstar = compute_time_to_steady(init_cond, k, steady_state)
% Set the options for the ODE solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-9);
% Define the ODE function as a nested function
function dcdt = ode_function(t, c)
dcdt = compute_ode(t, c, k);
end
% Initialize variables
tspan = [0 100000]; % Time range from 0 to 100,000
threshold = 0.001; % 1% error threshold
% Solve the ODE
[T, C] = ode45(@ode_function, tspan, init_cond, options);
% Iterate over the solution to find the first time it meets the criterion
for i = 1:length(T)
if abs(C(i) – steady_state) / steady_state < threshold
tstar = T(i);
return;
end
end
% If the criterion is not met within the time range, return the last time point
tstar = T(end);
end
function dcdt = compute_ode(t, c, k)
dcdt = 0.1 * (c – 20) * (23 – c) * (c – 26) + k;
end
function steady_states = compute_states(k)
% Define the steady state values based on the value of k
steady_states = [20; 23; 26];
end
I would really appriciate any help on computing the basin of attraction for a steady state!
Thank you! I need write a function called "compute_basin" that takes in a steady state and its k value and computes which set of initial conditions in [15,30] approach that steady state. Specifically it will return two values, "a" and "b", which describe the set [a,b] of initial conditions that approach the steady state. The function will be assessed by running
[a,b]=compute_basin(steady_state,k);
for many different values of k and the associated steady states.
Inputs:
a scalar value of a steady state
a scalar value of k (note the steady state should be correct for the k value)
Outputs:
a scalar for the lower bounds of the basin of attraction
a scalar for the upper bounds for the basin of attraction
This is what i have so far:
function [a, b] = compute_basin(Ceq, k)
% Initialize variables
a = 15; % Lower bound for the basin of attraction
b = 30; % Upper bound for the basin of attraction
threshold = 0.001; % Error threshold
% Binary search for the lower bound (a)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
right = mid;
else
left = mid + 0.1;
end
end
a = left;
% Binary search for the upper bound (b)
left = 15;
right = 30;
while left < right
mid = (left + right) / 2;
tstar = compute_time_to_steady(mid, k, Ceq);
if tstar > 0
left = mid;
else
right = mid – 0.1;
end
end
b = right;
end
But unfortunalty this is not correct. I have a tip saying that "There are many ways of doing this but a binary search algorithm might be helpful (Wikipedia entry for binary searchLinks to an external site.). Make sure that the [a,b] bounds are within the range of [15,30]. Note that some steady states may be unstable and so their basin of attraction will only be their exact value. In these cases a=b. It helps to solve for the upper and lower bounds separately, i.e. running the code for a and then running it again for b."
I have acces to three functions, the first is "compute_ode" that computes the derivative dC/dt for the differential equation model dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k.
function dcdt = compute_ode(t,c,k)
% write the equation for the differential equation and assign it to output dcdt
dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k;
end
Then i have the second "compute_states" that takes as input a value for k and then returns as output all real-valued steady states for the differential equation.
function vectCeq = compute_states(k)
% Coefficients of the polynomial equation -0.1*c^3 + 6.9*c^2 – 157.8*c + 1196 + k = 0
coeffs = [-0.1, 6.9, -157.8, 1196 + k];
% Find all roots of the polynomial
all_roots = roots(coeffs);
% Filter out complex roots
real_roots = all_roots(imag(all_roots) == 0);
% Return the real-valued steady states
vectCeq = real_roots;
end
And latsly, I have "compute_time_to_steady" that solves the differential equation and returns the earliest time it takes to get within 1% error of the steady state value:
function tstar = compute_time_to_steady(init_cond, k, steady_state)
% Set the options for the ODE solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-9);
% Define the ODE function as a nested function
function dcdt = ode_function(t, c)
dcdt = compute_ode(t, c, k);
end
% Initialize variables
tspan = [0 100000]; % Time range from 0 to 100,000
threshold = 0.001; % 1% error threshold
% Solve the ODE
[T, C] = ode45(@ode_function, tspan, init_cond, options);
% Iterate over the solution to find the first time it meets the criterion
for i = 1:length(T)
if abs(C(i) – steady_state) / steady_state < threshold
tstar = T(i);
return;
end
end
% If the criterion is not met within the time range, return the last time point
tstar = T(end);
end
function dcdt = compute_ode(t, c, k)
dcdt = 0.1 * (c – 20) * (23 – c) * (c – 26) + k;
end
function steady_states = compute_states(k)
% Define the steady state values based on the value of k
steady_states = [20; 23; 26];
end
I would really appriciate any help on computing the basin of attraction for a steady state!
Thank you! basin, ode, ode45, differential equations MATLAB Answers — New Questions
Matlab Grader not working when restore a Moodle course between sites
I have two different Moodle sites A and B (last update for LTS 4.1.x) with Matlab Grader working on both systems (a different deployment for each one).
Steps:
Create a Matlab Grader activity in a course in site A
Backup course in site A
Restore course in site B
Launch Matlab Grader activity in the new course at site B -> blank page.
Create and launch a new Matlab Grader activity in the same course at site B -> works OK.
Am I missing something I need to do on the restored course at site B for the Matlab Grader to work?
Thanks.I have two different Moodle sites A and B (last update for LTS 4.1.x) with Matlab Grader working on both systems (a different deployment for each one).
Steps:
Create a Matlab Grader activity in a course in site A
Backup course in site A
Restore course in site B
Launch Matlab Grader activity in the new course at site B -> blank page.
Create and launch a new Matlab Grader activity in the same course at site B -> works OK.
Am I missing something I need to do on the restored course at site B for the Matlab Grader to work?
Thanks. I have two different Moodle sites A and B (last update for LTS 4.1.x) with Matlab Grader working on both systems (a different deployment for each one).
Steps:
Create a Matlab Grader activity in a course in site A
Backup course in site A
Restore course in site B
Launch Matlab Grader activity in the new course at site B -> blank page.
Create and launch a new Matlab Grader activity in the same course at site B -> works OK.
Am I missing something I need to do on the restored course at site B for the Matlab Grader to work?
Thanks. matlab grader, backup, restore, moodle MATLAB Answers — New Questions
Visibility of Custom Library in Simulink
Hello everybody,
i´m having following problem with the custom library:
According to the site mentioned later i created a custom library with several blocks. Saving the custom library on a path iny my Matlab-Folder (not the Installation Folder) leads to the problem, that i can just access the library while the concerning folder is active in Simulink. Having a project in a different folder disables the accessibility. I also tried to create the custom library as a project and add this as a referenced project to the main project – but still it doesnt work.
My goal is to built up a bigger custom library with sub-libs, to which different projects (created by different persons) get access to. Of course there is the possibility of copying the needed sub-libs to the concerning projects. But by updating several blocks, the changes would need to be adjusted manually in existing projects (recopying the sub-lib), which use those blocks.
I hope i could explain my problem adequate
https://de.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.htmlHello everybody,
i´m having following problem with the custom library:
According to the site mentioned later i created a custom library with several blocks. Saving the custom library on a path iny my Matlab-Folder (not the Installation Folder) leads to the problem, that i can just access the library while the concerning folder is active in Simulink. Having a project in a different folder disables the accessibility. I also tried to create the custom library as a project and add this as a referenced project to the main project – but still it doesnt work.
My goal is to built up a bigger custom library with sub-libs, to which different projects (created by different persons) get access to. Of course there is the possibility of copying the needed sub-libs to the concerning projects. But by updating several blocks, the changes would need to be adjusted manually in existing projects (recopying the sub-lib), which use those blocks.
I hope i could explain my problem adequate
https://de.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.html Hello everybody,
i´m having following problem with the custom library:
According to the site mentioned later i created a custom library with several blocks. Saving the custom library on a path iny my Matlab-Folder (not the Installation Folder) leads to the problem, that i can just access the library while the concerning folder is active in Simulink. Having a project in a different folder disables the accessibility. I also tried to create the custom library as a project and add this as a referenced project to the main project – but still it doesnt work.
My goal is to built up a bigger custom library with sub-libs, to which different projects (created by different persons) get access to. Of course there is the possibility of copying the needed sub-libs to the concerning projects. But by updating several blocks, the changes would need to be adjusted manually in existing projects (recopying the sub-lib), which use those blocks.
I hope i could explain my problem adequate
https://de.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.html custom library MATLAB Answers — New Questions
MATLAB Visualizations broken?
Hello,
can anyone please check, if the MATLAB Visualizations are right now offline for everyone or just for me? I’ve made 2 visualizations and both show the "broken image" icon instead of the graph.
The problem occurred half an hour ago or so – I do not know exactly. As you can see, widgets are not affected. Both visualizations are public and can be "Save an Run" with "MATLAB code ran successfully." as status.
Here is one of the MATLAB codes that has worked flawless till it stopped:
% Template MATLAB code for visualizing data using the YYAXIS and PLOT functions.
% Prior to running this MATLAB code template, assign the channel variables.
% Set ‘readChannelID’ to the channel ID of the channel to read from.
% Also, assign the read field IDs to the variables ‘fieldID1’, and ‘fieldID2’.
% TODO – Replace the [] with channel ID to read data from:
readChannelID = [********];
% TODO – Replace the [] with the Field ID to read data from:
fieldID1 = [3];
% TODO – Replace the [] with the Field ID to read data from:
fieldID2 = [5];
% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the ” below:
readAPIKey = ‘***********’;
%% Read Data %%
% Read first data variable
[data1, time1] = thingSpeakRead(readChannelID, ‘Field’, fieldID1, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
% Read second data variable
[data2, time2] = thingSpeakRead(readChannelID, ‘Field’, fieldID2, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
%% Visualize Data %%
yyaxis left;
plot(time1, data1)
xlabel(‘Zeit’);
ylabel(‘Watt’);
yyaxis right;
plot(time2, data2);
xlabel(‘Zeit’);
ylabel(‘Ampere’);
title(‘Phase 2 – Watt & Ampere’);
grid on;
Any help is appreciated – thanks in advance!
MDHello,
can anyone please check, if the MATLAB Visualizations are right now offline for everyone or just for me? I’ve made 2 visualizations and both show the "broken image" icon instead of the graph.
The problem occurred half an hour ago or so – I do not know exactly. As you can see, widgets are not affected. Both visualizations are public and can be "Save an Run" with "MATLAB code ran successfully." as status.
Here is one of the MATLAB codes that has worked flawless till it stopped:
% Template MATLAB code for visualizing data using the YYAXIS and PLOT functions.
% Prior to running this MATLAB code template, assign the channel variables.
% Set ‘readChannelID’ to the channel ID of the channel to read from.
% Also, assign the read field IDs to the variables ‘fieldID1’, and ‘fieldID2’.
% TODO – Replace the [] with channel ID to read data from:
readChannelID = [********];
% TODO – Replace the [] with the Field ID to read data from:
fieldID1 = [3];
% TODO – Replace the [] with the Field ID to read data from:
fieldID2 = [5];
% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the ” below:
readAPIKey = ‘***********’;
%% Read Data %%
% Read first data variable
[data1, time1] = thingSpeakRead(readChannelID, ‘Field’, fieldID1, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
% Read second data variable
[data2, time2] = thingSpeakRead(readChannelID, ‘Field’, fieldID2, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
%% Visualize Data %%
yyaxis left;
plot(time1, data1)
xlabel(‘Zeit’);
ylabel(‘Watt’);
yyaxis right;
plot(time2, data2);
xlabel(‘Zeit’);
ylabel(‘Ampere’);
title(‘Phase 2 – Watt & Ampere’);
grid on;
Any help is appreciated – thanks in advance!
MD Hello,
can anyone please check, if the MATLAB Visualizations are right now offline for everyone or just for me? I’ve made 2 visualizations and both show the "broken image" icon instead of the graph.
The problem occurred half an hour ago or so – I do not know exactly. As you can see, widgets are not affected. Both visualizations are public and can be "Save an Run" with "MATLAB code ran successfully." as status.
Here is one of the MATLAB codes that has worked flawless till it stopped:
% Template MATLAB code for visualizing data using the YYAXIS and PLOT functions.
% Prior to running this MATLAB code template, assign the channel variables.
% Set ‘readChannelID’ to the channel ID of the channel to read from.
% Also, assign the read field IDs to the variables ‘fieldID1’, and ‘fieldID2’.
% TODO – Replace the [] with channel ID to read data from:
readChannelID = [********];
% TODO – Replace the [] with the Field ID to read data from:
fieldID1 = [3];
% TODO – Replace the [] with the Field ID to read data from:
fieldID2 = [5];
% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the ” below:
readAPIKey = ‘***********’;
%% Read Data %%
% Read first data variable
[data1, time1] = thingSpeakRead(readChannelID, ‘Field’, fieldID1, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
% Read second data variable
[data2, time2] = thingSpeakRead(readChannelID, ‘Field’, fieldID2, ‘NumPoints’, 600, ‘ReadKey’, readAPIKey);
%% Visualize Data %%
yyaxis left;
plot(time1, data1)
xlabel(‘Zeit’);
ylabel(‘Watt’);
yyaxis right;
plot(time2, data2);
xlabel(‘Zeit’);
ylabel(‘Ampere’);
title(‘Phase 2 – Watt & Ampere’);
grid on;
Any help is appreciated – thanks in advance!
MD thingspeak, visualizations, matlab MATLAB Answers — New Questions
If I have an array and I need to find an element in the array how do I go about it?
say states,
states = [1 0 0;
1 1 0
0 1 0
0 1 1
0 0 1
1 0 1
1 1 1];
C = 110;
How do I find the index of C in states and call it?
Ideally C is 2 then states(2) will give me 110 what key word can I use? or How do I go about it?say states,
states = [1 0 0;
1 1 0
0 1 0
0 1 1
0 0 1
1 0 1
1 1 1];
C = 110;
How do I find the index of C in states and call it?
Ideally C is 2 then states(2) will give me 110 what key word can I use? or How do I go about it? say states,
states = [1 0 0;
1 1 0
0 1 0
0 1 1
0 0 1
1 0 1
1 1 1];
C = 110;
How do I find the index of C in states and call it?
Ideally C is 2 then states(2) will give me 110 what key word can I use? or How do I go about it? array, index MATLAB Answers — New Questions
Object-Oriented: strange behavior that leads to shared reference
Hi, is my understanding of Matlab OO incorrect or something else is going on here ?
I cannot explain why this code assert :
Given this simple handle class :
classdef TestA < handle
properties
Name string = "default value for TestA";
end
end
An using it like this ( see the explicit size of 1,1 )
classdef TestB < handle
properties
PropA (1,1) TestA % please note the (1,1) size
end
end
An this test usage :
b1 = TestB;
b1.PropA.Name = "in b1 object";
b2 = TestB;
b2.PropA.Name = "in b2 object";
assert(b1.PropA ~= b2.PropA)
This assertion failling clearly state that the PropA property of both objects b1 and b2 is the same object.
Is this a documented behaviour ?
I was expecting to get a new TestA object in every TestB object.
note that we get the same strange behavior with this syntax:
classdef TestB2 < handle
properties
PropA (1,:) TestA = TestA % please note the (1,:) size
end
end
so you get the strange behavior and you loose the (1,1) size constraint.
This can be a workaround, but again, far from clean and still no size constraint
classdef TestB3 < handle
properties
PropA (1,:) TestA = TestA.empty() % please note the (1,:) size
end
methods
function obj = TestB3()
obj.PropA = TestA(); % explicitly create the object works
end
end
end
I can get the size constraint by using a Dependent property but this is so much code for something that basic…
Should i report a bug? or is it explained somewhere in the documentation ?Hi, is my understanding of Matlab OO incorrect or something else is going on here ?
I cannot explain why this code assert :
Given this simple handle class :
classdef TestA < handle
properties
Name string = "default value for TestA";
end
end
An using it like this ( see the explicit size of 1,1 )
classdef TestB < handle
properties
PropA (1,1) TestA % please note the (1,1) size
end
end
An this test usage :
b1 = TestB;
b1.PropA.Name = "in b1 object";
b2 = TestB;
b2.PropA.Name = "in b2 object";
assert(b1.PropA ~= b2.PropA)
This assertion failling clearly state that the PropA property of both objects b1 and b2 is the same object.
Is this a documented behaviour ?
I was expecting to get a new TestA object in every TestB object.
note that we get the same strange behavior with this syntax:
classdef TestB2 < handle
properties
PropA (1,:) TestA = TestA % please note the (1,:) size
end
end
so you get the strange behavior and you loose the (1,1) size constraint.
This can be a workaround, but again, far from clean and still no size constraint
classdef TestB3 < handle
properties
PropA (1,:) TestA = TestA.empty() % please note the (1,:) size
end
methods
function obj = TestB3()
obj.PropA = TestA(); % explicitly create the object works
end
end
end
I can get the size constraint by using a Dependent property but this is so much code for something that basic…
Should i report a bug? or is it explained somewhere in the documentation ? Hi, is my understanding of Matlab OO incorrect or something else is going on here ?
I cannot explain why this code assert :
Given this simple handle class :
classdef TestA < handle
properties
Name string = "default value for TestA";
end
end
An using it like this ( see the explicit size of 1,1 )
classdef TestB < handle
properties
PropA (1,1) TestA % please note the (1,1) size
end
end
An this test usage :
b1 = TestB;
b1.PropA.Name = "in b1 object";
b2 = TestB;
b2.PropA.Name = "in b2 object";
assert(b1.PropA ~= b2.PropA)
This assertion failling clearly state that the PropA property of both objects b1 and b2 is the same object.
Is this a documented behaviour ?
I was expecting to get a new TestA object in every TestB object.
note that we get the same strange behavior with this syntax:
classdef TestB2 < handle
properties
PropA (1,:) TestA = TestA % please note the (1,:) size
end
end
so you get the strange behavior and you loose the (1,1) size constraint.
This can be a workaround, but again, far from clean and still no size constraint
classdef TestB3 < handle
properties
PropA (1,:) TestA = TestA.empty() % please note the (1,:) size
end
methods
function obj = TestB3()
obj.PropA = TestA(); % explicitly create the object works
end
end
end
I can get the size constraint by using a Dependent property but this is so much code for something that basic…
Should i report a bug? or is it explained somewhere in the documentation ? object-oriented MATLAB Answers — New Questions