Author: PuTI
How to create a CCS ToolchainInfo object in Matlab2023?
I am connecting CCS6.2 to Matlab2023b, but i’m getting an error when i use code "ticcs(‘boardnum’,0, ‘procnum’, 0)" to identify F2812 board. I used it by Matlab2011 and i didn’t have any problem. Anyone can help me please?
I want to create a CCS object in the matlab GUI host program, so that I can control the start and stop of the DSP and the transmission of data after the model is automatically generated into code.I am connecting CCS6.2 to Matlab2023b, but i’m getting an error when i use code "ticcs(‘boardnum’,0, ‘procnum’, 0)" to identify F2812 board. I used it by Matlab2011 and i didn’t have any problem. Anyone can help me please?
I want to create a CCS object in the matlab GUI host program, so that I can control the start and stop of the DSP and the transmission of data after the model is automatically generated into code. I am connecting CCS6.2 to Matlab2023b, but i’m getting an error when i use code "ticcs(‘boardnum’,0, ‘procnum’, 0)" to identify F2812 board. I used it by Matlab2011 and i didn’t have any problem. Anyone can help me please?
I want to create a CCS object in the matlab GUI host program, so that I can control the start and stop of the DSP and the transmission of data after the model is automatically generated into code. matlab, simulink, ccs, dsp, ticcs MATLAB Answers — New Questions
Does anyone know how to connect the ccsv6 with the Matlab2015a, using the prompt command? I’m using the ticcs but it didn’t work.
cc = ticcs
Registering DLLs…
IDE Link successfully registered its plug-in for Code Composer Studio (CCS).
If CCS prompts you that "New components were detected,"
click Yes or OK in the prompt dialog box to enable components
for all compatible CCS installations.
Error using Link.ccssetup/Connect
Cannot start CCS application (COM error ID: 0x80040154). Verify that your CCS software is installed and configured
properly.
Error in ticcs>Connect2App_CheckIdeVersion (line 244)
hccs.Connect(1);
Error in ticcs (line 132)
hccs = Connect2App_CheckIdeVersion;cc = ticcs
Registering DLLs…
IDE Link successfully registered its plug-in for Code Composer Studio (CCS).
If CCS prompts you that "New components were detected,"
click Yes or OK in the prompt dialog box to enable components
for all compatible CCS installations.
Error using Link.ccssetup/Connect
Cannot start CCS application (COM error ID: 0x80040154). Verify that your CCS software is installed and configured
properly.
Error in ticcs>Connect2App_CheckIdeVersion (line 244)
hccs.Connect(1);
Error in ticcs (line 132)
hccs = Connect2App_CheckIdeVersion; cc = ticcs
Registering DLLs…
IDE Link successfully registered its plug-in for Code Composer Studio (CCS).
If CCS prompts you that "New components were detected,"
click Yes or OK in the prompt dialog box to enable components
for all compatible CCS installations.
Error using Link.ccssetup/Connect
Cannot start CCS application (COM error ID: 0x80040154). Verify that your CCS software is installed and configured
properly.
Error in ticcs>Connect2App_CheckIdeVersion (line 244)
hccs.Connect(1);
Error in ticcs (line 132)
hccs = Connect2App_CheckIdeVersion; target, ticcs, f28335, embedded matlab function MATLAB Answers — New Questions
Rapid Accelerator and sldrt.tlc compile issue: Code Generation and simulation targets registered different sets of persistent variables for the block.
Hello,
When I run my code with normal or accelerator mode or compile using grt.tlc my model executes succesfully. If I attempt to use rapid accelerator or sldrt.tlc, I receive this error:
Code generation and simulation targets registered different sets of persistent variables for the block. External or Rapid Accelerator mode simulation requires code generation and simulation targets to register the same set of persistent variables for this block. This discrepancy is typically caused by MATLAB functions that have different code paths for simulation and code generation targets where these code paths define different sets of persistent variables. Please identify these code paths in the offending block and rewrite the MATLAB code so that the set of persistent variables is the same between simulation and code generation.
This model is based almost entirely around stateflow and simply imports data from a binary file reader.
Things I’ve tried:
Completely removed persistent variables from called matlab functions
Followed this heirarchy for compiling matlab functions, made everything a subfunction, and then removed all extra files from the folder location. https://www.mathworks.com/help/coder/ug/how-matlab-resolves-function-calls-in-generated-code.html
Tried various other compiling targets. Embedded coder returns a sizing error that I don’t intend to fix currently.grt.tlc works great.
I can’t find any information on the 2 seperate paths the error is referring to so I would be interested in knowing if that’s a setting somewhere.Hello,
When I run my code with normal or accelerator mode or compile using grt.tlc my model executes succesfully. If I attempt to use rapid accelerator or sldrt.tlc, I receive this error:
Code generation and simulation targets registered different sets of persistent variables for the block. External or Rapid Accelerator mode simulation requires code generation and simulation targets to register the same set of persistent variables for this block. This discrepancy is typically caused by MATLAB functions that have different code paths for simulation and code generation targets where these code paths define different sets of persistent variables. Please identify these code paths in the offending block and rewrite the MATLAB code so that the set of persistent variables is the same between simulation and code generation.
This model is based almost entirely around stateflow and simply imports data from a binary file reader.
Things I’ve tried:
Completely removed persistent variables from called matlab functions
Followed this heirarchy for compiling matlab functions, made everything a subfunction, and then removed all extra files from the folder location. https://www.mathworks.com/help/coder/ug/how-matlab-resolves-function-calls-in-generated-code.html
Tried various other compiling targets. Embedded coder returns a sizing error that I don’t intend to fix currently.grt.tlc works great.
I can’t find any information on the 2 seperate paths the error is referring to so I would be interested in knowing if that’s a setting somewhere. Hello,
When I run my code with normal or accelerator mode or compile using grt.tlc my model executes succesfully. If I attempt to use rapid accelerator or sldrt.tlc, I receive this error:
Code generation and simulation targets registered different sets of persistent variables for the block. External or Rapid Accelerator mode simulation requires code generation and simulation targets to register the same set of persistent variables for this block. This discrepancy is typically caused by MATLAB functions that have different code paths for simulation and code generation targets where these code paths define different sets of persistent variables. Please identify these code paths in the offending block and rewrite the MATLAB code so that the set of persistent variables is the same between simulation and code generation.
This model is based almost entirely around stateflow and simply imports data from a binary file reader.
Things I’ve tried:
Completely removed persistent variables from called matlab functions
Followed this heirarchy for compiling matlab functions, made everything a subfunction, and then removed all extra files from the folder location. https://www.mathworks.com/help/coder/ug/how-matlab-resolves-function-calls-in-generated-code.html
Tried various other compiling targets. Embedded coder returns a sizing error that I don’t intend to fix currently.grt.tlc works great.
I can’t find any information on the 2 seperate paths the error is referring to so I would be interested in knowing if that’s a setting somewhere. simulink, stateflow, persistent variables, pathing MATLAB Answers — New Questions
Hello everyone, please help me with this error Error:Invalid
Error:Invalid setting for input port dimensions of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Demux3’. The dimensions are being set to 1440. This is not valid because the total number of input and output elements are not the same
Error:Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 2’ of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Real-Imag to Complex’.Error:Invalid setting for input port dimensions of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Demux3’. The dimensions are being set to 1440. This is not valid because the total number of input and output elements are not the same
Error:Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 2’ of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Real-Imag to Complex’. Error:Invalid setting for input port dimensions of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Demux3’. The dimensions are being set to 1440. This is not valid because the total number of input and output elements are not the same
Error:Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 2’ of ‘VPP_5_3_2025/Three-Phase Dynamic Load/Model/Real-Imag to Complex’. error, demux, three-phase dynamic load MATLAB Answers — New Questions
What is the relationship between the simulation time tf in simulink and the actual running time of the system? If my system needs to run 800s before it can be stable, then tf
What is the relationship between the simulation time tf in simulink and the actual running time of the system? If my system needs to run 800s before it can be stable, then tf in simulink must also be 800s, or I just need 800 steps, then the simulation time tf can be 80s, and the sampling time ts can be 0.1s, is that right? I don’t understand, because if I set the simulation time tf to 800s, it will take me a very long time to train with reinforcement learning.What is the relationship between the simulation time tf in simulink and the actual running time of the system? If my system needs to run 800s before it can be stable, then tf in simulink must also be 800s, or I just need 800 steps, then the simulation time tf can be 80s, and the sampling time ts can be 0.1s, is that right? I don’t understand, because if I set the simulation time tf to 800s, it will take me a very long time to train with reinforcement learning. What is the relationship between the simulation time tf in simulink and the actual running time of the system? If my system needs to run 800s before it can be stable, then tf in simulink must also be 800s, or I just need 800 steps, then the simulation time tf can be 80s, and the sampling time ts can be 0.1s, is that right? I don’t understand, because if I set the simulation time tf to 800s, it will take me a very long time to train with reinforcement learning. simulation time tf sampling time ts maxsteps MATLAB Answers — New Questions
Model Info in Matlab 2023b Simulink does not start displaying from top
Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow.Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow. Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow. model-info MATLAB Answers — New Questions
Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b?
Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation.Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation. Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation. 32 bit b, rh850/f1km-s1, matlab 2022b MATLAB Answers — New Questions
Hello, after logging into your account I get an error: Oops! This page is currently unavailable. Error Code: MHOD-4XX And she’s been out for over a week now, what should I do?
Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do?Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do? Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do? matlab MATLAB Answers — New Questions
How i can graph in 3 dimension, dependent of the temperature?
Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time.Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time. Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time. 3d plots, plot, temperature, room MATLAB Answers — New Questions
How does the UAV Toolbox interact with NuttX scheduling?
Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority.Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority. Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority. nuttx, px4, uavtoolbox, scheduling, priority MATLAB Answers — New Questions
How can I use complex numbers and non-finite number in PLC Coder?
Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC.Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC. Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC. nonfinitenumber, infinity, inf, nan, beckhoff, plc, complexnumbers, polynomialsolutions MATLAB Answers — New Questions
Getting error installing Matlab on Linux
I’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too shortI’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too short I’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too short installation MATLAB Answers — New Questions
lorentz attractors in matlab using online and clouds rf transmitters
hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot.hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot. hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot. lorentz, attractors, transmitters, matlab, simulink MATLAB Answers — New Questions
Python GUI doesn’t close after closing MATLAB
Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications?Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications? Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications? matlab, pyrunfile MATLAB Answers — New Questions
Grading multiple different but correct answers in MATLAB Grader
Hello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
PrabhakarHello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
Prabhakar Hello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
Prabhakar matlab grader MATLAB Answers — New Questions
Give me images of the code bellow
* Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]);* Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]); * Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]); image processing MATLAB Answers — New Questions
Issue with Time-Domain Shifting Using Fourier Shift Property in MATLAB
I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks!I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks! I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks! fft, fourier shifting property MATLAB Answers — New Questions
Is the generated symbol or schematic in Simscape Multi-Winding Transformer misrepresented?
Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth:Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth: Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth: simscape MATLAB Answers — New Questions
How do I print a sentence “Hello world!” n number of times?
n is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanksn is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanks n is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanks fprintf, for, input, script, homework MATLAB Answers — New Questions
How can I create a singleton object that is processed in parallel threads and processes?
What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above?What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above? What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above? singleton, parallel computing, parallel computing toolbox, handles MATLAB Answers — New Questions