Month: January 2025
How to remove DC component in FFT?
I succesfully plotted my FFT with MATLAB discussion help. Now I could not remove the DC component at 0Hz. Which shows me a very high amplitude. Can any one suggest me an idea?
data1 = xlsread(‘Reading 1.xlsx’) ; %Loading Sensor data from Excel file
t = data1 (1:512,2); %Selecting Time vector
s = data1 (1:512,3); %Selecting Z axis vibrations
L = numel(t); %Signal length
Ts = mean(diff(t)); %Sampling interval
Fs = 1/Ts; %Sampling frequency
Fn = Fs/2; %Nyquist frequency
FTs = fft(s)/L; %Fast fourier transform (s- data)
Fv = linspace(0,1, fix(L/2)+1)*Fn; %Frequency vector
Iv = 1:numel(Fv); %Index vector
subplot(2, 1, 1); %plotting top pane
plot(t,s); %Acceleration vs time
set(gca,’xlim’,[1 50]); %Scale to fit
grid; %Grids on
title (‘Acceleration vs time’);
xlabel(‘time(s)’);
ylabel(‘Acceleration’);
subplot(2, 1, 2); %Plotting bottom pane
plot(Fv, abs(FTs(Iv))*2,’red’); %FFT – Amplitude vs Frequency
grid
title (‘Fast fourier transform’);
xlabel(‘Frequency (Hz)’);
ylabel (‘Amplitude (m)’);I succesfully plotted my FFT with MATLAB discussion help. Now I could not remove the DC component at 0Hz. Which shows me a very high amplitude. Can any one suggest me an idea?
data1 = xlsread(‘Reading 1.xlsx’) ; %Loading Sensor data from Excel file
t = data1 (1:512,2); %Selecting Time vector
s = data1 (1:512,3); %Selecting Z axis vibrations
L = numel(t); %Signal length
Ts = mean(diff(t)); %Sampling interval
Fs = 1/Ts; %Sampling frequency
Fn = Fs/2; %Nyquist frequency
FTs = fft(s)/L; %Fast fourier transform (s- data)
Fv = linspace(0,1, fix(L/2)+1)*Fn; %Frequency vector
Iv = 1:numel(Fv); %Index vector
subplot(2, 1, 1); %plotting top pane
plot(t,s); %Acceleration vs time
set(gca,’xlim’,[1 50]); %Scale to fit
grid; %Grids on
title (‘Acceleration vs time’);
xlabel(‘time(s)’);
ylabel(‘Acceleration’);
subplot(2, 1, 2); %Plotting bottom pane
plot(Fv, abs(FTs(Iv))*2,’red’); %FFT – Amplitude vs Frequency
grid
title (‘Fast fourier transform’);
xlabel(‘Frequency (Hz)’);
ylabel (‘Amplitude (m)’); I succesfully plotted my FFT with MATLAB discussion help. Now I could not remove the DC component at 0Hz. Which shows me a very high amplitude. Can any one suggest me an idea?
data1 = xlsread(‘Reading 1.xlsx’) ; %Loading Sensor data from Excel file
t = data1 (1:512,2); %Selecting Time vector
s = data1 (1:512,3); %Selecting Z axis vibrations
L = numel(t); %Signal length
Ts = mean(diff(t)); %Sampling interval
Fs = 1/Ts; %Sampling frequency
Fn = Fs/2; %Nyquist frequency
FTs = fft(s)/L; %Fast fourier transform (s- data)
Fv = linspace(0,1, fix(L/2)+1)*Fn; %Frequency vector
Iv = 1:numel(Fv); %Index vector
subplot(2, 1, 1); %plotting top pane
plot(t,s); %Acceleration vs time
set(gca,’xlim’,[1 50]); %Scale to fit
grid; %Grids on
title (‘Acceleration vs time’);
xlabel(‘time(s)’);
ylabel(‘Acceleration’);
subplot(2, 1, 2); %Plotting bottom pane
plot(Fv, abs(FTs(Iv))*2,’red’); %FFT – Amplitude vs Frequency
grid
title (‘Fast fourier transform’);
xlabel(‘Frequency (Hz)’);
ylabel (‘Amplitude (m)’); dc, fft, amplitude MATLAB Answers — New Questions
How do I import my MATLAB path preferences when I install MATLAB on new computers?
I have a new computer with Matlab 2024b newly installed on it and am looking to import preference settings (mainly desktop layouts, font settings, and keyboard shortcuts) that I use in my Matlab installations on other computers. I am aware of this previous thread, but it is not applicable here, because it assumes that a previous release of Matlab resides on the computer. That is not the case for me, as the intended computer is brand new.
I have been able to import my desktop layouts manually by copying over the ___Layout.xml files that reside in the prefdir. However, I am not sure which prefdir file holds the fonts and keyboard shortcuts, so I have not been able to import those. Does anyone know which prefdir files are the applicable ones? I have tried copying over matlab.prf, but it doesn’t seem to have any effect.I have a new computer with Matlab 2024b newly installed on it and am looking to import preference settings (mainly desktop layouts, font settings, and keyboard shortcuts) that I use in my Matlab installations on other computers. I am aware of this previous thread, but it is not applicable here, because it assumes that a previous release of Matlab resides on the computer. That is not the case for me, as the intended computer is brand new.
I have been able to import my desktop layouts manually by copying over the ___Layout.xml files that reside in the prefdir. However, I am not sure which prefdir file holds the fonts and keyboard shortcuts, so I have not been able to import those. Does anyone know which prefdir files are the applicable ones? I have tried copying over matlab.prf, but it doesn’t seem to have any effect. I have a new computer with Matlab 2024b newly installed on it and am looking to import preference settings (mainly desktop layouts, font settings, and keyboard shortcuts) that I use in my Matlab installations on other computers. I am aware of this previous thread, but it is not applicable here, because it assumes that a previous release of Matlab resides on the computer. That is not the case for me, as the intended computer is brand new.
I have been able to import my desktop layouts manually by copying over the ___Layout.xml files that reside in the prefdir. However, I am not sure which prefdir file holds the fonts and keyboard shortcuts, so I have not been able to import those. Does anyone know which prefdir files are the applicable ones? I have tried copying over matlab.prf, but it doesn’t seem to have any effect. preferences, desktop, prefdir, keyboard shortcuts, fonts MATLAB Answers — New Questions
Command Window prompt stays in view during Run Section
I find, in R2024b (I haven’t checked other versions), then when running sub-sections of code, for example with , the command line prompt stays visible while the computation is in progress. This is not the case when running normally, and I am wondering if it is a deliberate design choice. If so, I wonder if there is some preference setting that will deactivate this, as I find it makes it a bit more difficult to see when Matlab is busy (in spite of the ‘Busy’ notification in the lower left of the Matlab desktop).I find, in R2024b (I haven’t checked other versions), then when running sub-sections of code, for example with , the command line prompt stays visible while the computation is in progress. This is not the case when running normally, and I am wondering if it is a deliberate design choice. If so, I wonder if there is some preference setting that will deactivate this, as I find it makes it a bit more difficult to see when Matlab is busy (in spite of the ‘Busy’ notification in the lower left of the Matlab desktop). I find, in R2024b (I haven’t checked other versions), then when running sub-sections of code, for example with , the command line prompt stays visible while the computation is in progress. This is not the case when running normally, and I am wondering if it is a deliberate design choice. If so, I wonder if there is some preference setting that will deactivate this, as I find it makes it a bit more difficult to see when Matlab is busy (in spite of the ‘Busy’ notification in the lower left of the Matlab desktop). run section, prompt MATLAB Answers — New Questions
Is MATLAB supported on iPad, iPhone, iPod Touch?
Is it possible to download and install MATLAB to an iPad, iPhone, or iPod Touch?Is it possible to download and install MATLAB to an iPad, iPhone, or iPod Touch? Is it possible to download and install MATLAB to an iPad, iPhone, or iPod Touch? MATLAB Answers — New Questions
Plot large files with timestamp
I have a large file and try to load it into MATLAB and plot it with timestamp.I have a large file and try to load it into MATLAB and plot it with timestamp. I have a large file and try to load it into MATLAB and plot it with timestamp. timestamp, plot MATLAB Answers — New Questions
How to handle big files
I have huge files and i want to know how i can handle them. Is splitting the big file the only option i have?I have huge files and i want to know how i can handle them. Is splitting the big file the only option i have? I have huge files and i want to know how i can handle them. Is splitting the big file the only option i have? big csv MATLAB Answers — New Questions
plot subplots axes configuration
Hello, i have some data and tried to plot them all in one figure without axes. So far so good but I want all subplots to have one common x-axis. Any ideas?Hello, i have some data and tried to plot them all in one figure without axes. So far so good but I want all subplots to have one common x-axis. Any ideas? Hello, i have some data and tried to plot them all in one figure without axes. So far so good but I want all subplots to have one common x-axis. Any ideas? common xy axes subplot MATLAB Answers — New Questions
Import and plot file with day and time information
I have a file and i cannot manage to plot my data correctly. I can plot values as datapoints but i need also the time.. Anyone who can help?I have a file and i cannot manage to plot my data correctly. I can plot values as datapoints but i need also the time.. Anyone who can help? I have a file and i cannot manage to plot my data correctly. I can plot values as datapoints but i need also the time.. Anyone who can help? csv plot, timestamp plot MATLAB Answers — New Questions
Split into different columns a file with characters ‘?’
I have a large file and need to import it into 13 collumns.
Any help?I have a large file and need to import it into 13 collumns.
Any help? I have a large file and need to import it into 13 collumns.
Any help? .csv MATLAB Answers — New Questions
Group data based on direct
I have a table with values and I want to group them in sectors. Is it possible to do it automatically either than manually?I have a table with values and I want to group them in sectors. Is it possible to do it automatically either than manually? I have a table with values and I want to group them in sectors. Is it possible to do it automatically either than manually? sectors, group MATLAB Answers — New Questions
Call to download server failed (HTTP error code: 403).
The installer for a compiled (using R2015b) app, that has been distributed to many customers for several years, is suddenly (noticed in last couple of days) throwing the above exception. This has happened from multiple sites, domestic and international. The installer is set up to download the MCR from MathWorks.
Is anyone aware of any MathWorks, Windows (10, 11) updates that might be causing this?
Thanks! It’s a bit urgent!!The installer for a compiled (using R2015b) app, that has been distributed to many customers for several years, is suddenly (noticed in last couple of days) throwing the above exception. This has happened from multiple sites, domestic and international. The installer is set up to download the MCR from MathWorks.
Is anyone aware of any MathWorks, Windows (10, 11) updates that might be causing this?
Thanks! It’s a bit urgent!! The installer for a compiled (using R2015b) app, that has been distributed to many customers for several years, is suddenly (noticed in last couple of days) throwing the above exception. This has happened from multiple sites, domestic and international. The installer is set up to download the MCR from MathWorks.
Is anyone aware of any MathWorks, Windows (10, 11) updates that might be causing this?
Thanks! It’s a bit urgent!! http, code 403, download server MATLAB Answers — New Questions
Improve part of code using a loop
I have an annual table X, where I want to calculate the maximum values for each month. My code works but I need to apply it for other variables so I am wondering how make a loop?I have an annual table X, where I want to calculate the maximum values for each month. My code works but I need to apply it for other variables so I am wondering how make a loop? I have an annual table X, where I want to calculate the maximum values for each month. My code works but I need to apply it for other variables so I am wondering how make a loop? loop MATLAB Answers — New Questions
Calculate the maximum and minimum values
Hello I have a big timetable I want to calculate the maximum and minimum values
Any ideas how to proceed?Hello I have a big timetable I want to calculate the maximum and minimum values
Any ideas how to proceed? Hello I have a big timetable I want to calculate the maximum and minimum values
Any ideas how to proceed? max, timestamp MATLAB Answers — New Questions
Calculate daily standard deviation from timetable
Hello, I want to calculate the mean max and mean min standard deviation of temperature data from a daily timetable.
How can I calculate the standard deviation for each day?Hello, I want to calculate the mean max and mean min standard deviation of temperature data from a daily timetable.
How can I calculate the standard deviation for each day? Hello, I want to calculate the mean max and mean min standard deviation of temperature data from a daily timetable.
How can I calculate the standard deviation for each day? sd, timetables MATLAB Answers — New Questions
Partial Differential Equation Solver with Dynamic Boundary conditions
P0 = 101325; % Atmospheric pressure (Pa)
C1 = 10;
C2 = 62.29;
C3 = 62.29;
C4 = 0.557;
C5 = 2391.3;
C6 = 0.609;
omega_i = 0.008; % Inlet humidity ratio (kg/kg dry air)
Tg_i = 303.15; % Inlet air temperature (K)
% Initial conditions
Ts_init = Tg_i;
omega_s_init = 0.008; % solid humidity ratio
omega_o_init = omega_i;
Tg_o_init = Tg_i;
% Sim parameters
N = 180; % Angular resolution
theta = linspace(0, 180, N); % Angular positions in degrees
dt = 1 / (15.5 * 60) / N; % Time step for rotation
tspan = [0, dt * N]; % Simulation time
% ODE system to access constants
function dYdt = desiccant_wheel_ode(t, Y)
% Unpack variables
omega_o = Y(1);
Ts = Y(2);
Tg_o = Y(3);
omega_s = Y(4);
% Saturation pressure and relative humidity
Ps = exp(5294 / Ts – 6); % Saturation pressure (Pa)
phi = (omega_s / 0.622) * P0 / ((0.622 + omega_s) * Ps);
% Empirical functions
s1 = (0.24 / 1.5) * (phi^0.333) * (0.622 * P0) / ((0.622 + omega_s)^2 * Ps);
s2 = (0.24 / 1.5) * (phi^0.333) * (5294 * phi) / (Ts^2);
% Differential equations
d_omega_dt = C1 * (omega_i – omega_o) + C2 * (omega_s – omega_o);
d_Ts_dt = C4 * C5 * (omega_o – omega_s) + C6 * (Tg_o – Ts);
d_Tg_dt = C1 * (Tg_i – Tg_o) + C3 * (Ts – Tg_o);
d_omega_s_dt = (s2 / s1) * d_Ts_dt + (C4 / s1) * (omega_o – omega_s);
% Output derivatives
dYdt = [d_omega_dt; d_Ts_dt; d_Tg_dt; d_omega_s_dt];
end
% ODE ode45
Y0 = [omega_o_init, Ts_init, Tg_o_init, omega_s_init]; % Initial conditions
[t, Y] = ode45(@desiccant_wheel_ode, tspan, Y0);
% Extract results
omega_o = Y(:, 1) * 1000; % Convert to g/kg dry air
Ts = Y(:, 2) – 273.15; % temp to °C
% Plot data
figure;
plot(theta, omega_o, ‘k’, ‘LineWidth’, 2);
xlabel(‘Degree’);
ylabel(‘Humidity [g/kg dry air]’);
title(‘Adsorption-side Outlet Humidity Ratio’);
grid on;P0 = 101325; % Atmospheric pressure (Pa)
C1 = 10;
C2 = 62.29;
C3 = 62.29;
C4 = 0.557;
C5 = 2391.3;
C6 = 0.609;
omega_i = 0.008; % Inlet humidity ratio (kg/kg dry air)
Tg_i = 303.15; % Inlet air temperature (K)
% Initial conditions
Ts_init = Tg_i;
omega_s_init = 0.008; % solid humidity ratio
omega_o_init = omega_i;
Tg_o_init = Tg_i;
% Sim parameters
N = 180; % Angular resolution
theta = linspace(0, 180, N); % Angular positions in degrees
dt = 1 / (15.5 * 60) / N; % Time step for rotation
tspan = [0, dt * N]; % Simulation time
% ODE system to access constants
function dYdt = desiccant_wheel_ode(t, Y)
% Unpack variables
omega_o = Y(1);
Ts = Y(2);
Tg_o = Y(3);
omega_s = Y(4);
% Saturation pressure and relative humidity
Ps = exp(5294 / Ts – 6); % Saturation pressure (Pa)
phi = (omega_s / 0.622) * P0 / ((0.622 + omega_s) * Ps);
% Empirical functions
s1 = (0.24 / 1.5) * (phi^0.333) * (0.622 * P0) / ((0.622 + omega_s)^2 * Ps);
s2 = (0.24 / 1.5) * (phi^0.333) * (5294 * phi) / (Ts^2);
% Differential equations
d_omega_dt = C1 * (omega_i – omega_o) + C2 * (omega_s – omega_o);
d_Ts_dt = C4 * C5 * (omega_o – omega_s) + C6 * (Tg_o – Ts);
d_Tg_dt = C1 * (Tg_i – Tg_o) + C3 * (Ts – Tg_o);
d_omega_s_dt = (s2 / s1) * d_Ts_dt + (C4 / s1) * (omega_o – omega_s);
% Output derivatives
dYdt = [d_omega_dt; d_Ts_dt; d_Tg_dt; d_omega_s_dt];
end
% ODE ode45
Y0 = [omega_o_init, Ts_init, Tg_o_init, omega_s_init]; % Initial conditions
[t, Y] = ode45(@desiccant_wheel_ode, tspan, Y0);
% Extract results
omega_o = Y(:, 1) * 1000; % Convert to g/kg dry air
Ts = Y(:, 2) – 273.15; % temp to °C
% Plot data
figure;
plot(theta, omega_o, ‘k’, ‘LineWidth’, 2);
xlabel(‘Degree’);
ylabel(‘Humidity [g/kg dry air]’);
title(‘Adsorption-side Outlet Humidity Ratio’);
grid on; P0 = 101325; % Atmospheric pressure (Pa)
C1 = 10;
C2 = 62.29;
C3 = 62.29;
C4 = 0.557;
C5 = 2391.3;
C6 = 0.609;
omega_i = 0.008; % Inlet humidity ratio (kg/kg dry air)
Tg_i = 303.15; % Inlet air temperature (K)
% Initial conditions
Ts_init = Tg_i;
omega_s_init = 0.008; % solid humidity ratio
omega_o_init = omega_i;
Tg_o_init = Tg_i;
% Sim parameters
N = 180; % Angular resolution
theta = linspace(0, 180, N); % Angular positions in degrees
dt = 1 / (15.5 * 60) / N; % Time step for rotation
tspan = [0, dt * N]; % Simulation time
% ODE system to access constants
function dYdt = desiccant_wheel_ode(t, Y)
% Unpack variables
omega_o = Y(1);
Ts = Y(2);
Tg_o = Y(3);
omega_s = Y(4);
% Saturation pressure and relative humidity
Ps = exp(5294 / Ts – 6); % Saturation pressure (Pa)
phi = (omega_s / 0.622) * P0 / ((0.622 + omega_s) * Ps);
% Empirical functions
s1 = (0.24 / 1.5) * (phi^0.333) * (0.622 * P0) / ((0.622 + omega_s)^2 * Ps);
s2 = (0.24 / 1.5) * (phi^0.333) * (5294 * phi) / (Ts^2);
% Differential equations
d_omega_dt = C1 * (omega_i – omega_o) + C2 * (omega_s – omega_o);
d_Ts_dt = C4 * C5 * (omega_o – omega_s) + C6 * (Tg_o – Ts);
d_Tg_dt = C1 * (Tg_i – Tg_o) + C3 * (Ts – Tg_o);
d_omega_s_dt = (s2 / s1) * d_Ts_dt + (C4 / s1) * (omega_o – omega_s);
% Output derivatives
dYdt = [d_omega_dt; d_Ts_dt; d_Tg_dt; d_omega_s_dt];
end
% ODE ode45
Y0 = [omega_o_init, Ts_init, Tg_o_init, omega_s_init]; % Initial conditions
[t, Y] = ode45(@desiccant_wheel_ode, tspan, Y0);
% Extract results
omega_o = Y(:, 1) * 1000; % Convert to g/kg dry air
Ts = Y(:, 2) – 273.15; % temp to °C
% Plot data
figure;
plot(theta, omega_o, ‘k’, ‘LineWidth’, 2);
xlabel(‘Degree’);
ylabel(‘Humidity [g/kg dry air]’);
title(‘Adsorption-side Outlet Humidity Ratio’);
grid on; desiccant wheel MATLAB Answers — New Questions
H5G__traverse_real component not found
When running this chunk of code on a Windows 10 pc (Lenovo) in Matlab 2021 b release:
clear
pathFileActivityScan = ‘F:/Dati/…/000001/’;
pathFileNetwork = ‘F:/Dati/…/data.raw.h5/’;
networkDataInfo = h5info(pathFileNetwork);
% the raw signal (first 5000 samples for e.g. 100 channels)
rawpath = ‘/recordings/rec0000/well000/groups/routed’;
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
% a smaller chunk of data (between 4000 and 5000 samples for e.g. 100 channels)
networkRawData2 = h5read(pathFileNetwork,[rawpath ‘/raw’],[4000 1],[1000 100]);
% the spikes that were detected and stored by the software
networkSpikes = h5read(pathFileNetwork,’/recordings/rec0000/well000/spikes’);
I got this error messagge:
Error using h5readc
The HDF5 library encountered an error and produced the following stack trace information:
H5G__traverse_real component not found
Error in h5read (line 93)
[data,var_class] = h5read(Filename,Dataset,start,count,stride);
Error in the script I’m using (line 33)
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
Where do you think the problem could be? It gives me no cue of it.When running this chunk of code on a Windows 10 pc (Lenovo) in Matlab 2021 b release:
clear
pathFileActivityScan = ‘F:/Dati/…/000001/’;
pathFileNetwork = ‘F:/Dati/…/data.raw.h5/’;
networkDataInfo = h5info(pathFileNetwork);
% the raw signal (first 5000 samples for e.g. 100 channels)
rawpath = ‘/recordings/rec0000/well000/groups/routed’;
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
% a smaller chunk of data (between 4000 and 5000 samples for e.g. 100 channels)
networkRawData2 = h5read(pathFileNetwork,[rawpath ‘/raw’],[4000 1],[1000 100]);
% the spikes that were detected and stored by the software
networkSpikes = h5read(pathFileNetwork,’/recordings/rec0000/well000/spikes’);
I got this error messagge:
Error using h5readc
The HDF5 library encountered an error and produced the following stack trace information:
H5G__traverse_real component not found
Error in h5read (line 93)
[data,var_class] = h5read(Filename,Dataset,start,count,stride);
Error in the script I’m using (line 33)
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
Where do you think the problem could be? It gives me no cue of it. When running this chunk of code on a Windows 10 pc (Lenovo) in Matlab 2021 b release:
clear
pathFileActivityScan = ‘F:/Dati/…/000001/’;
pathFileNetwork = ‘F:/Dati/…/data.raw.h5/’;
networkDataInfo = h5info(pathFileNetwork);
% the raw signal (first 5000 samples for e.g. 100 channels)
rawpath = ‘/recordings/rec0000/well000/groups/routed’;
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
% a smaller chunk of data (between 4000 and 5000 samples for e.g. 100 channels)
networkRawData2 = h5read(pathFileNetwork,[rawpath ‘/raw’],[4000 1],[1000 100]);
% the spikes that were detected and stored by the software
networkSpikes = h5read(pathFileNetwork,’/recordings/rec0000/well000/spikes’);
I got this error messagge:
Error using h5readc
The HDF5 library encountered an error and produced the following stack trace information:
H5G__traverse_real component not found
Error in h5read (line 93)
[data,var_class] = h5read(Filename,Dataset,start,count,stride);
Error in the script I’m using (line 33)
networkRawData = h5read(pathFileNetwork,[rawpath ‘/raw’],[1 1],[5000 100]);
Where do you think the problem could be? It gives me no cue of it. h5, h5read, matlab, traverse_real MATLAB Answers — New Questions
GA Function non linear Constraints decrease Initial Population to 1 ?
Dear Matlab users,
I am currently having a problem to define the nonlinear constraints.
The point of problem is with nonlinear constraints, it doesnt’ keep the number of initial population to fitnessfunction and left even only one individual.
But without nonlinear constraints option it keeps 45 individuals.
Please take a look this codes and may very greatful, when you write me any small tips.
size(InitPop) = 45
Vectorized= ‘on’
1. Starting InitialPopulation [45,9]
options = optimoptions(@ga, ‘PopulationSize’, 45, ‘InitialPopulation’, InitPop, …
‘PopulationType’, ‘doubleVector’, ”MaxStallGenerations’, 10, …
‘FunctionTolerance’, 1e-03, ‘MaxGenerations’, 100, ‘Vectorized’, ‘on’);
2.
[Value, fval, ~, output] = ga(@fitnessfunction, nvars, [], [], [], [], lb,ub, @nonlincon, [], options);
3. Definition of nonlinear constraints
function [c, ceq] = nonlincon(x)
c = 3 – (x(:, 1) + 3 * tan(x(:, 2)));% 3 – (x1 + 3tan(x2)) <= 0
ceq = [];
end
Thank you so much for time
Best regards.Dear Matlab users,
I am currently having a problem to define the nonlinear constraints.
The point of problem is with nonlinear constraints, it doesnt’ keep the number of initial population to fitnessfunction and left even only one individual.
But without nonlinear constraints option it keeps 45 individuals.
Please take a look this codes and may very greatful, when you write me any small tips.
size(InitPop) = 45
Vectorized= ‘on’
1. Starting InitialPopulation [45,9]
options = optimoptions(@ga, ‘PopulationSize’, 45, ‘InitialPopulation’, InitPop, …
‘PopulationType’, ‘doubleVector’, ”MaxStallGenerations’, 10, …
‘FunctionTolerance’, 1e-03, ‘MaxGenerations’, 100, ‘Vectorized’, ‘on’);
2.
[Value, fval, ~, output] = ga(@fitnessfunction, nvars, [], [], [], [], lb,ub, @nonlincon, [], options);
3. Definition of nonlinear constraints
function [c, ceq] = nonlincon(x)
c = 3 – (x(:, 1) + 3 * tan(x(:, 2)));% 3 – (x1 + 3tan(x2)) <= 0
ceq = [];
end
Thank you so much for time
Best regards. Dear Matlab users,
I am currently having a problem to define the nonlinear constraints.
The point of problem is with nonlinear constraints, it doesnt’ keep the number of initial population to fitnessfunction and left even only one individual.
But without nonlinear constraints option it keeps 45 individuals.
Please take a look this codes and may very greatful, when you write me any small tips.
size(InitPop) = 45
Vectorized= ‘on’
1. Starting InitialPopulation [45,9]
options = optimoptions(@ga, ‘PopulationSize’, 45, ‘InitialPopulation’, InitPop, …
‘PopulationType’, ‘doubleVector’, ”MaxStallGenerations’, 10, …
‘FunctionTolerance’, 1e-03, ‘MaxGenerations’, 100, ‘Vectorized’, ‘on’);
2.
[Value, fval, ~, output] = ga(@fitnessfunction, nvars, [], [], [], [], lb,ub, @nonlincon, [], options);
3. Definition of nonlinear constraints
function [c, ceq] = nonlincon(x)
c = 3 – (x(:, 1) + 3 * tan(x(:, 2)));% 3 – (x1 + 3tan(x2)) <= 0
ceq = [];
end
Thank you so much for time
Best regards. ga, genetic algorithm, optimization MATLAB Answers — New Questions
Match matrix values with mesh nodes
I’ve obtained mesh on an image, and I have a color intensity matrix of the same image. Matrix values I want to multiply with Modulus of Elasticity value and then match them with the numbers of mesh nodes/elements according to their position, and import the result into ANSYS. The matrix and the mesh are attached below.
Mesh is obtained using im2mesh by JieXian Ma. It’s represented as a n-by-2 array of nodes (x and y positions), m-by-3 array of triangles (positions of 3 nodes forming a triangle) and m-by-1 array of grayscale phases (phases are initially selected to generate a mesh according to an intensity of gray color)
As I understand, there should be a loop which:
checks the position of a mesh node (x and y)
checks the position of a value in the matrix (row and column)
assigns the value of a matrix to the node (a new array with these values)
Or does the same, but with an element instead of a node (with averaged coordinate between nodes)
But I may be wrong, as I’m new in Matlab
And I don’t know how to make this loop properly, because the matrix is a square with many values equal to 0 (it initially was 255 and represented air, I just inversed the values so the air is represented as pure black color), while mesh is made differently and doesn’t include empty region (which is air)
I hope I explained it well. If you don’t understand something, please tell meI’ve obtained mesh on an image, and I have a color intensity matrix of the same image. Matrix values I want to multiply with Modulus of Elasticity value and then match them with the numbers of mesh nodes/elements according to their position, and import the result into ANSYS. The matrix and the mesh are attached below.
Mesh is obtained using im2mesh by JieXian Ma. It’s represented as a n-by-2 array of nodes (x and y positions), m-by-3 array of triangles (positions of 3 nodes forming a triangle) and m-by-1 array of grayscale phases (phases are initially selected to generate a mesh according to an intensity of gray color)
As I understand, there should be a loop which:
checks the position of a mesh node (x and y)
checks the position of a value in the matrix (row and column)
assigns the value of a matrix to the node (a new array with these values)
Or does the same, but with an element instead of a node (with averaged coordinate between nodes)
But I may be wrong, as I’m new in Matlab
And I don’t know how to make this loop properly, because the matrix is a square with many values equal to 0 (it initially was 255 and represented air, I just inversed the values so the air is represented as pure black color), while mesh is made differently and doesn’t include empty region (which is air)
I hope I explained it well. If you don’t understand something, please tell me I’ve obtained mesh on an image, and I have a color intensity matrix of the same image. Matrix values I want to multiply with Modulus of Elasticity value and then match them with the numbers of mesh nodes/elements according to their position, and import the result into ANSYS. The matrix and the mesh are attached below.
Mesh is obtained using im2mesh by JieXian Ma. It’s represented as a n-by-2 array of nodes (x and y positions), m-by-3 array of triangles (positions of 3 nodes forming a triangle) and m-by-1 array of grayscale phases (phases are initially selected to generate a mesh according to an intensity of gray color)
As I understand, there should be a loop which:
checks the position of a mesh node (x and y)
checks the position of a value in the matrix (row and column)
assigns the value of a matrix to the node (a new array with these values)
Or does the same, but with an element instead of a node (with averaged coordinate between nodes)
But I may be wrong, as I’m new in Matlab
And I don’t know how to make this loop properly, because the matrix is a square with many values equal to 0 (it initially was 255 and represented air, I just inversed the values so the air is represented as pure black color), while mesh is made differently and doesn’t include empty region (which is air)
I hope I explained it well. If you don’t understand something, please tell me image processing, fea, mesh MATLAB Answers — New Questions
Cassegrain Antenna Design Errors
I’m trying to run the attached code for a Cassegrain antenna, changing the frequency from 18 GHz to the GPS frequencies 1575.42 MHz and 1227.6 MHz. I changed the frequencies and the following errors came up: "Error in em.MeshGeometry/updateMesh, Error in em.MeshGeometry/getMesh, and Error in em.EmStructures/analyze". Can you help resolve the errors?
Rp=0.3175;
fp=0.2536;
Rsub=0.033;
fhyp=0.1416;
ant=cassegrain(‘Radius’,[Rp Rsub],’FocalLength’,[fp fhyp]);
show(ant);
Exciter=design(hornConical,17.7e9);
Exciter.FeedWidth=3.4e-3;
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
show(Exciter);
ant=reflectorParabolic(‘Radius’,0.3175);
ant.Exciter=design(hornConical,17.7e9);
ant.Exciter.Tilt=90;
figure;
pattern(ant,18e9);
ant=cassegrain;
s=sparameters(ant,linspace(18e9,18.8e9,25));
figure;rfplot(s);
figure;
impedance(ant,linspace(18e9,18.8e9,25));
current(ant,18e9,’scale’,’log10′);
Exciter=design(horn,16.2e9);
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
ant.Exciter=Exciter;
show(ant);
figure;
pattern(ant,18e9);I’m trying to run the attached code for a Cassegrain antenna, changing the frequency from 18 GHz to the GPS frequencies 1575.42 MHz and 1227.6 MHz. I changed the frequencies and the following errors came up: "Error in em.MeshGeometry/updateMesh, Error in em.MeshGeometry/getMesh, and Error in em.EmStructures/analyze". Can you help resolve the errors?
Rp=0.3175;
fp=0.2536;
Rsub=0.033;
fhyp=0.1416;
ant=cassegrain(‘Radius’,[Rp Rsub],’FocalLength’,[fp fhyp]);
show(ant);
Exciter=design(hornConical,17.7e9);
Exciter.FeedWidth=3.4e-3;
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
show(Exciter);
ant=reflectorParabolic(‘Radius’,0.3175);
ant.Exciter=design(hornConical,17.7e9);
ant.Exciter.Tilt=90;
figure;
pattern(ant,18e9);
ant=cassegrain;
s=sparameters(ant,linspace(18e9,18.8e9,25));
figure;rfplot(s);
figure;
impedance(ant,linspace(18e9,18.8e9,25));
current(ant,18e9,’scale’,’log10′);
Exciter=design(horn,16.2e9);
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
ant.Exciter=Exciter;
show(ant);
figure;
pattern(ant,18e9); I’m trying to run the attached code for a Cassegrain antenna, changing the frequency from 18 GHz to the GPS frequencies 1575.42 MHz and 1227.6 MHz. I changed the frequencies and the following errors came up: "Error in em.MeshGeometry/updateMesh, Error in em.MeshGeometry/getMesh, and Error in em.EmStructures/analyze". Can you help resolve the errors?
Rp=0.3175;
fp=0.2536;
Rsub=0.033;
fhyp=0.1416;
ant=cassegrain(‘Radius’,[Rp Rsub],’FocalLength’,[fp fhyp]);
show(ant);
Exciter=design(hornConical,17.7e9);
Exciter.FeedWidth=3.4e-3;
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
show(Exciter);
ant=reflectorParabolic(‘Radius’,0.3175);
ant.Exciter=design(hornConical,17.7e9);
ant.Exciter.Tilt=90;
figure;
pattern(ant,18e9);
ant=cassegrain;
s=sparameters(ant,linspace(18e9,18.8e9,25));
figure;rfplot(s);
figure;
impedance(ant,linspace(18e9,18.8e9,25));
current(ant,18e9,’scale’,’log10′);
Exciter=design(horn,16.2e9);
Exciter.Tilt=270;
Exciter.TiltAxis=[0 1 0];
ant.Exciter=Exciter;
show(ant);
figure;
pattern(ant,18e9); cassegrain errors MATLAB Answers — New Questions
Ensuring Non-Negativity and Constraints Satisfaction in Regression with ReLU in MATLAB
Hello, MathWorks community,
I am currently working on a deep learning neural network for a regression problem using MATLAB R2023a. My dataset consists of three inputs and four outputs. The data has been split into training (80%) and testing (20%) subsets.
I am using the ReLU activation function in my network, and the training process is implemented via the TrainNetwork function. For predictions, I utilize the predict function to generate the four outputs based on the test data.
There are two points should be noted which are:
The actual (target) outputs for both training and testing datasets are always non-negative (i.e., ≥0).
A specific relationship must hold between the inputs and actual outputs for every instance in the dataset, given as:
(Input #3+Output #1+Output #4) − (Input #1+Input #2+Output #2+Output #3) = 0 (Think about it as balance constraint)
My questions are:
How can I ensure that the predicted outputs generated by the neural network are always non-negative?
How can I guarantee that the predicted outputs strictly satisfy the above relationship with the inputs ?
Any suggestions, insights, or example implementations would be greatly appreciated.
Thank you in advance for your help!
Best regards,Hello, MathWorks community,
I am currently working on a deep learning neural network for a regression problem using MATLAB R2023a. My dataset consists of three inputs and four outputs. The data has been split into training (80%) and testing (20%) subsets.
I am using the ReLU activation function in my network, and the training process is implemented via the TrainNetwork function. For predictions, I utilize the predict function to generate the four outputs based on the test data.
There are two points should be noted which are:
The actual (target) outputs for both training and testing datasets are always non-negative (i.e., ≥0).
A specific relationship must hold between the inputs and actual outputs for every instance in the dataset, given as:
(Input #3+Output #1+Output #4) − (Input #1+Input #2+Output #2+Output #3) = 0 (Think about it as balance constraint)
My questions are:
How can I ensure that the predicted outputs generated by the neural network are always non-negative?
How can I guarantee that the predicted outputs strictly satisfy the above relationship with the inputs ?
Any suggestions, insights, or example implementations would be greatly appreciated.
Thank you in advance for your help!
Best regards, Hello, MathWorks community,
I am currently working on a deep learning neural network for a regression problem using MATLAB R2023a. My dataset consists of three inputs and four outputs. The data has been split into training (80%) and testing (20%) subsets.
I am using the ReLU activation function in my network, and the training process is implemented via the TrainNetwork function. For predictions, I utilize the predict function to generate the four outputs based on the test data.
There are two points should be noted which are:
The actual (target) outputs for both training and testing datasets are always non-negative (i.e., ≥0).
A specific relationship must hold between the inputs and actual outputs for every instance in the dataset, given as:
(Input #3+Output #1+Output #4) − (Input #1+Input #2+Output #2+Output #3) = 0 (Think about it as balance constraint)
My questions are:
How can I ensure that the predicted outputs generated by the neural network are always non-negative?
How can I guarantee that the predicted outputs strictly satisfy the above relationship with the inputs ?
Any suggestions, insights, or example implementations would be greatly appreciated.
Thank you in advance for your help!
Best regards, deep learning, regression MATLAB Answers — New Questions