Month: January 2025
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
How to solve the following four integration in MATLAB
Hello all, I am trying to solve the following expression involving four integrations in MATLAB but note getting it correctly.
This is how I had tried to code:
integrand = @(y, h, z1, z2) (1 / gamma(m_0)) * …
gammainc( ((u_1 ./ …
(a_1 * zeta_1 * y .* g_1_abs_sq .* h .* P_h1_2 – …
u_1 * a_2 * zeta_1 * y .* g_1_abs_sq .* h .*P_h1_2 – …
u_1 * a_1 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_1 * zeta_1 *P_h1_2 * z2 .* g_1_abs_sq .* h – …
u_1 * a_2 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_2 * zeta_1 * P_h1_2 * z2 .* g_1_abs_sq .* h)) / …
(Omega_0 / m_0)),m_0) .* …
(1/gamma(m_0))*((m_0/Omega_0)^m_0)*y^(m_0-1)*exp(-m_0*y/Omega_0).* 1/(2*pi*A_1).*lambda_1*exp(-lambda_1*z1).*lambda_2*exp(-lambda_2*z2);
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
% Perform the integration
op = integral(outer_integral, 0, 1000);
I am not getting why I am getting such errors:
Not enough input arguments.
Error in Analytical_2>@(z1,z2)(P_h1_2*(a_1-u_1*a_2))./(u_1*a_1*z1+u_1*a_1*P_h1_2*z2+u_1*a_2*z1+u_1*a_2*P_h1_2*z2) (line 96)
(u_1 * a_1 * z1 + u_1 * a_1 * P_h1_2 * z2 + …
Error in Analytical_2>@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in Analytical_2>@(z2)arrayfun(@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)),0:1000) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in Analytical_2 (line 136)
op = integral(outer_integral, 0, 1000);
Please note that I had intentionally not given other part of code which is used to produce the values of elements that are used in this integrand. Any help in this regard will be highly appreciated.Hello all, I am trying to solve the following expression involving four integrations in MATLAB but note getting it correctly.
This is how I had tried to code:
integrand = @(y, h, z1, z2) (1 / gamma(m_0)) * …
gammainc( ((u_1 ./ …
(a_1 * zeta_1 * y .* g_1_abs_sq .* h .* P_h1_2 – …
u_1 * a_2 * zeta_1 * y .* g_1_abs_sq .* h .*P_h1_2 – …
u_1 * a_1 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_1 * zeta_1 *P_h1_2 * z2 .* g_1_abs_sq .* h – …
u_1 * a_2 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_2 * zeta_1 * P_h1_2 * z2 .* g_1_abs_sq .* h)) / …
(Omega_0 / m_0)),m_0) .* …
(1/gamma(m_0))*((m_0/Omega_0)^m_0)*y^(m_0-1)*exp(-m_0*y/Omega_0).* 1/(2*pi*A_1).*lambda_1*exp(-lambda_1*z1).*lambda_2*exp(-lambda_2*z2);
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
% Perform the integration
op = integral(outer_integral, 0, 1000);
I am not getting why I am getting such errors:
Not enough input arguments.
Error in Analytical_2>@(z1,z2)(P_h1_2*(a_1-u_1*a_2))./(u_1*a_1*z1+u_1*a_1*P_h1_2*z2+u_1*a_2*z1+u_1*a_2*P_h1_2*z2) (line 96)
(u_1 * a_1 * z1 + u_1 * a_1 * P_h1_2 * z2 + …
Error in Analytical_2>@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in Analytical_2>@(z2)arrayfun(@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)),0:1000) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in Analytical_2 (line 136)
op = integral(outer_integral, 0, 1000);
Please note that I had intentionally not given other part of code which is used to produce the values of elements that are used in this integrand. Any help in this regard will be highly appreciated. Hello all, I am trying to solve the following expression involving four integrations in MATLAB but note getting it correctly.
This is how I had tried to code:
integrand = @(y, h, z1, z2) (1 / gamma(m_0)) * …
gammainc( ((u_1 ./ …
(a_1 * zeta_1 * y .* g_1_abs_sq .* h .* P_h1_2 – …
u_1 * a_2 * zeta_1 * y .* g_1_abs_sq .* h .*P_h1_2 – …
u_1 * a_1 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_1 * zeta_1 *P_h1_2 * z2 .* g_1_abs_sq .* h – …
u_1 * a_2 * zeta_1 * g_1_abs_sq .* h .* z1 – …
u_1 * a_2 * zeta_1 * P_h1_2 * z2 .* g_1_abs_sq .* h)) / …
(Omega_0 / m_0)),m_0) .* …
(1/gamma(m_0))*((m_0/Omega_0)^m_0)*y^(m_0-1)*exp(-m_0*y/Omega_0).* 1/(2*pi*A_1).*lambda_1*exp(-lambda_1*z1).*lambda_2*exp(-lambda_2*z2);
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
% Perform the integration
op = integral(outer_integral, 0, 1000);
I am not getting why I am getting such errors:
Not enough input arguments.
Error in Analytical_2>@(z1,z2)(P_h1_2*(a_1-u_1*a_2))./(u_1*a_1*z1+u_1*a_1*P_h1_2*z2+u_1*a_2*z1+u_1*a_2*P_h1_2*z2) (line 96)
(u_1 * a_1 * z1 + u_1 * a_1 * P_h1_2 * z2 + …
Error in Analytical_2>@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in Analytical_2>@(z2)arrayfun(@(z2_val)integral(@(y,h,z1)integrand(y,h,z1,z2_val),0,y_max(z2_val)),0:1000) (line 132)
outer_integral = @(z2) arrayfun(@(z2_val) integral(@(y,h,z1) integrand(y,h,z1,z2_val ), 0, y_max(z2_val)), 0:1000);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in Analytical_2 (line 136)
op = integral(outer_integral, 0, 1000);
Please note that I had intentionally not given other part of code which is used to produce the values of elements that are used in this integrand. Any help in this regard will be highly appreciated. integration, multiple integration, matlab, for loop, function MATLAB Answers — New Questions
how can i convert pixels into cms,the code that is available online is giving error
thia is the code that i m using.pixe
cmPerPixel = distanceInCm / distanceInPixels;
% Now to convert a distance.
lengthInCm = lengthInPixels * cmPerPixel
% And to convert an area in pixels to square cm:
areaInSquareCm = areaInPixels * cmPerPixel ^ 2thia is the code that i m using.pixe
cmPerPixel = distanceInCm / distanceInPixels;
% Now to convert a distance.
lengthInCm = lengthInPixels * cmPerPixel
% And to convert an area in pixels to square cm:
areaInSquareCm = areaInPixels * cmPerPixel ^ 2 thia is the code that i m using.pixe
cmPerPixel = distanceInCm / distanceInPixels;
% Now to convert a distance.
lengthInCm = lengthInPixels * cmPerPixel
% And to convert an area in pixels to square cm:
areaInSquareCm = areaInPixels * cmPerPixel ^ 2 pixels into cms, spatial calibration MATLAB Answers — New Questions
Integral command doesn’t work inside the for loop
Hello. I have this simple code trying to compare analytical solution of few functions with two numerical methods. I used for loop wih the integral command in it but i get many errors.
clear, clc, close all, format long
a = 0;
b = 2;
h1 = b – a;
h2 = (b – a)/2;
n = 1:5;
fprintf(‘tAnalyticaltTrapezoidtSimpsonnn’)
for i = 1:length(n)
f = @(x) x.^n;
I = integral(f,a,b);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gtttt%gttt%gn’,I(i),Trap(i),Simp(i))
end
f = @(x) exp(x);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gttt%gtt%gn’,I,Trap,Simp)Hello. I have this simple code trying to compare analytical solution of few functions with two numerical methods. I used for loop wih the integral command in it but i get many errors.
clear, clc, close all, format long
a = 0;
b = 2;
h1 = b – a;
h2 = (b – a)/2;
n = 1:5;
fprintf(‘tAnalyticaltTrapezoidtSimpsonnn’)
for i = 1:length(n)
f = @(x) x.^n;
I = integral(f,a,b);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gtttt%gttt%gn’,I(i),Trap(i),Simp(i))
end
f = @(x) exp(x);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gttt%gtt%gn’,I,Trap,Simp) Hello. I have this simple code trying to compare analytical solution of few functions with two numerical methods. I used for loop wih the integral command in it but i get many errors.
clear, clc, close all, format long
a = 0;
b = 2;
h1 = b – a;
h2 = (b – a)/2;
n = 1:5;
fprintf(‘tAnalyticaltTrapezoidtSimpsonnn’)
for i = 1:length(n)
f = @(x) x.^n;
I = integral(f,a,b);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gtttt%gttt%gn’,I(i),Trap(i),Simp(i))
end
f = @(x) exp(x);
Trap = 0.5*h1*(f(a) + f(b));
Simp = (h2/3)*(f(a) + 4*f(h2) + f(b));
fprintf(‘t%gttt%gtt%gn’,I,Trap,Simp) numerical integration, trapezoid rule, simpson rule, integral command MATLAB Answers — New Questions
how to plot different range of files on one graph using hold on
i have 63 .mat files that contain cells of data. i am dividing the .mat files into three parts so that each file is plotted correspondingly on the same graph from another set. that is, file 1 in the first, second third set are plotted on the same graph using hold on and the same for file 2 and so on. Although, i have not included the plot command, i am still trying to see how the code looks like by dividing the files into two sets.
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
count2 = 0;
filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUMttrttr1tt4*.mat’);
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
spectrum = load(filelist(fileidx).name);
C = spectrum.B
% second set of files
for fileidx1 = startIndex1:endIndex1
count2 = count2+1;
if count2 == count1
spectrum1 = load(filelist(fileidx1).name);
C1 = spectrum.B
end
end
% but the output is not favourable.i have 63 .mat files that contain cells of data. i am dividing the .mat files into three parts so that each file is plotted correspondingly on the same graph from another set. that is, file 1 in the first, second third set are plotted on the same graph using hold on and the same for file 2 and so on. Although, i have not included the plot command, i am still trying to see how the code looks like by dividing the files into two sets.
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
count2 = 0;
filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUMttrttr1tt4*.mat’);
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
spectrum = load(filelist(fileidx).name);
C = spectrum.B
% second set of files
for fileidx1 = startIndex1:endIndex1
count2 = count2+1;
if count2 == count1
spectrum1 = load(filelist(fileidx1).name);
C1 = spectrum.B
end
end
% but the output is not favourable. i have 63 .mat files that contain cells of data. i am dividing the .mat files into three parts so that each file is plotted correspondingly on the same graph from another set. that is, file 1 in the first, second third set are plotted on the same graph using hold on and the same for file 2 and so on. Although, i have not included the plot command, i am still trying to see how the code looks like by dividing the files into two sets.
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
count2 = 0;
filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUMttrttr1tt4*.mat’);
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
spectrum = load(filelist(fileidx).name);
C = spectrum.B
% second set of files
for fileidx1 = startIndex1:endIndex1
count2 = count2+1;
if count2 == count1
spectrum1 = load(filelist(fileidx1).name);
C1 = spectrum.B
end
end
% but the output is not favourable. file indexing, for loop hold on MATLAB Answers — New Questions
Is There A Way to Rename the “app” Component In appdesigner?
When you start appdesigner, the canvas window contains a single UIFigure. You can access the UIFigure via syntax like "app.UIFigure…" So the main component I think is the "app" component (or main ‘object’, I’m not sure I have the correct phrasing). I want to rename the "app" component to "A" such that I would then access the UIFigure via syntax like "A.UIFigure…".
Is it possible to rename "app" to "A" and how is it done.
Thanks in advance.When you start appdesigner, the canvas window contains a single UIFigure. You can access the UIFigure via syntax like "app.UIFigure…" So the main component I think is the "app" component (or main ‘object’, I’m not sure I have the correct phrasing). I want to rename the "app" component to "A" such that I would then access the UIFigure via syntax like "A.UIFigure…".
Is it possible to rename "app" to "A" and how is it done.
Thanks in advance. When you start appdesigner, the canvas window contains a single UIFigure. You can access the UIFigure via syntax like "app.UIFigure…" So the main component I think is the "app" component (or main ‘object’, I’m not sure I have the correct phrasing). I want to rename the "app" component to "A" such that I would then access the UIFigure via syntax like "A.UIFigure…".
Is it possible to rename "app" to "A" and how is it done.
Thanks in advance. appdesigner, app designer, components MATLAB Answers — New Questions
How to add TCL script to HDL Coder IP Core generation
I use HDL Coder IP Core flow and I need to add a TCL script that I have to open Vivado, add the new IP core to the existing project and implement with it.
I tried "add additional sources" option in HDL Coder to point to my TCL script there. The TCL script was never executed.
Of course I can run the script manually after IP core is generated, but I want to have a pushbutton solution, such that I only start IP Core generation and everything else would work automatically.
One possible way would be to do everything (including IP core generation) in a TCL script, but I don’t know how to make HDL coder to generate IP core in a TCL script.
Any suggestions?
Thank you, alexI use HDL Coder IP Core flow and I need to add a TCL script that I have to open Vivado, add the new IP core to the existing project and implement with it.
I tried "add additional sources" option in HDL Coder to point to my TCL script there. The TCL script was never executed.
Of course I can run the script manually after IP core is generated, but I want to have a pushbutton solution, such that I only start IP Core generation and everything else would work automatically.
One possible way would be to do everything (including IP core generation) in a TCL script, but I don’t know how to make HDL coder to generate IP core in a TCL script.
Any suggestions?
Thank you, alex I use HDL Coder IP Core flow and I need to add a TCL script that I have to open Vivado, add the new IP core to the existing project and implement with it.
I tried "add additional sources" option in HDL Coder to point to my TCL script there. The TCL script was never executed.
Of course I can run the script manually after IP core is generated, but I want to have a pushbutton solution, such that I only start IP Core generation and everything else would work automatically.
One possible way would be to do everything (including IP core generation) in a TCL script, but I don’t know how to make HDL coder to generate IP core in a TCL script.
Any suggestions?
Thank you, alex hdl coder, ip core, tcl script, tcl command MATLAB Answers — New Questions
filtfilt initial condition calculation … can someone explain it?
Can someone explain how to get from the article "Determining the initial states in forward-backward filtering, IEEE Transactions on Signal Processing" to the initial condition calculation used in the filtfilt function?
As far as I understand the article, the calculation works by finding inital values that minimize the difference between forward-backward and backward-forward application of the filter.
But how does this translate into the formula used in filtfilt and the extrapolation by reflection?
Could the extrapolation by reflection be replaced by chosing different initial conditions? The initial conditions of the filter reflect all the memory it has of previous samples.Can someone explain how to get from the article "Determining the initial states in forward-backward filtering, IEEE Transactions on Signal Processing" to the initial condition calculation used in the filtfilt function?
As far as I understand the article, the calculation works by finding inital values that minimize the difference between forward-backward and backward-forward application of the filter.
But how does this translate into the formula used in filtfilt and the extrapolation by reflection?
Could the extrapolation by reflection be replaced by chosing different initial conditions? The initial conditions of the filter reflect all the memory it has of previous samples. Can someone explain how to get from the article "Determining the initial states in forward-backward filtering, IEEE Transactions on Signal Processing" to the initial condition calculation used in the filtfilt function?
As far as I understand the article, the calculation works by finding inital values that minimize the difference between forward-backward and backward-forward application of the filter.
But how does this translate into the formula used in filtfilt and the extrapolation by reflection?
Could the extrapolation by reflection be replaced by chosing different initial conditions? The initial conditions of the filter reflect all the memory it has of previous samples. filtfilt MATLAB Answers — New Questions
can you please explain the logic of this code
function alphaKrow = mkpca(data,sigma,numev)
% ———————————————————————– %
global K
[n, d] = size(data);
% n : number of data points
% d : dimension of data points
sigma = 2.5;
% kernel matrix:
K = zeros(n,n);
% kernel parameter:
param = 0.5/(sigma*sigma);
% fprintf(‘computing kernel matrix Kn’);
for i=1:n
for j=i:n
K(i,j) = kernel(data(i,:),data(j,:),param);
K(j,i) = K(i,j);
end
end
% correct K for non-zero center of data in feature space:
Krow = sum(K,1)/n;
Ksum = sum(Krow)/n;
for i=1:n
for j=1:n
K(i,j) = K(i,j) – Krow(i) – Krow(j) + Ksum;
end
end
opts.disp = 0;
[alpha,lambda] = eigs(K);
% normalize alpha:
alpha = alpha * inv(sqrt(lambda));
% compute some helper vectors:
alphaKrow = Krow * alpha;
K = imresize(K,[256,256]);
% ———————————————————————– %
function k = kernel(x,y,param)
% ———————————————————————– %
diff = x-y;
k = exp(-(diff * diff’)*param);function alphaKrow = mkpca(data,sigma,numev)
% ———————————————————————– %
global K
[n, d] = size(data);
% n : number of data points
% d : dimension of data points
sigma = 2.5;
% kernel matrix:
K = zeros(n,n);
% kernel parameter:
param = 0.5/(sigma*sigma);
% fprintf(‘computing kernel matrix Kn’);
for i=1:n
for j=i:n
K(i,j) = kernel(data(i,:),data(j,:),param);
K(j,i) = K(i,j);
end
end
% correct K for non-zero center of data in feature space:
Krow = sum(K,1)/n;
Ksum = sum(Krow)/n;
for i=1:n
for j=1:n
K(i,j) = K(i,j) – Krow(i) – Krow(j) + Ksum;
end
end
opts.disp = 0;
[alpha,lambda] = eigs(K);
% normalize alpha:
alpha = alpha * inv(sqrt(lambda));
% compute some helper vectors:
alphaKrow = Krow * alpha;
K = imresize(K,[256,256]);
% ———————————————————————– %
function k = kernel(x,y,param)
% ———————————————————————– %
diff = x-y;
k = exp(-(diff * diff’)*param); function alphaKrow = mkpca(data,sigma,numev)
% ———————————————————————– %
global K
[n, d] = size(data);
% n : number of data points
% d : dimension of data points
sigma = 2.5;
% kernel matrix:
K = zeros(n,n);
% kernel parameter:
param = 0.5/(sigma*sigma);
% fprintf(‘computing kernel matrix Kn’);
for i=1:n
for j=i:n
K(i,j) = kernel(data(i,:),data(j,:),param);
K(j,i) = K(i,j);
end
end
% correct K for non-zero center of data in feature space:
Krow = sum(K,1)/n;
Ksum = sum(Krow)/n;
for i=1:n
for j=1:n
K(i,j) = K(i,j) – Krow(i) – Krow(j) + Ksum;
end
end
opts.disp = 0;
[alpha,lambda] = eigs(K);
% normalize alpha:
alpha = alpha * inv(sqrt(lambda));
% compute some helper vectors:
alphaKrow = Krow * alpha;
K = imresize(K,[256,256]);
% ———————————————————————– %
function k = kernel(x,y,param)
% ———————————————————————– %
diff = x-y;
k = exp(-(diff * diff’)*param); pca MATLAB Answers — New Questions
can anyone explain me dis gaussian low pass filter coding
[M N]=size(A);
R=10;
X=0:N-1;
Y=0:M-1;
[X Y]=meshgrid(X,Y);
Cx=0.5*N;
Cy=0.5*M;
Lo=exp(-((X-Cx).^2+(Y-Cy).^2)./(2*R).^2);
Hi=1-Lo;
J=A1.*Lo;
J1=ifftshift(J);
B1=ifft2(J1);
K=A1.*Hi;
K1=ifftshift(K);
B2=ifft2(K1);[M N]=size(A);
R=10;
X=0:N-1;
Y=0:M-1;
[X Y]=meshgrid(X,Y);
Cx=0.5*N;
Cy=0.5*M;
Lo=exp(-((X-Cx).^2+(Y-Cy).^2)./(2*R).^2);
Hi=1-Lo;
J=A1.*Lo;
J1=ifftshift(J);
B1=ifft2(J1);
K=A1.*Hi;
K1=ifftshift(K);
B2=ifft2(K1); [M N]=size(A);
R=10;
X=0:N-1;
Y=0:M-1;
[X Y]=meshgrid(X,Y);
Cx=0.5*N;
Cy=0.5*M;
Lo=exp(-((X-Cx).^2+(Y-Cy).^2)./(2*R).^2);
Hi=1-Lo;
J=A1.*Lo;
J1=ifftshift(J);
B1=ifft2(J1);
K=A1.*Hi;
K1=ifftshift(K);
B2=ifft2(K1); gaussian low pass filter, gaussian, low pass filter MATLAB Answers — New Questions
Simple circuit does not work
I am a novice in Simulink and electric circuits
The attached simple model does not initialize.
I cannot figure out why.
Any hint is welcome.
Best regardsI am a novice in Simulink and electric circuits
The attached simple model does not initialize.
I cannot figure out why.
Any hint is welcome.
Best regards I am a novice in Simulink and electric circuits
The attached simple model does not initialize.
I cannot figure out why.
Any hint is welcome.
Best regards electric circuits MATLAB Answers — New Questions
Please explain ‘statsfminbx’ function ?
The maximum likelihood estimation of factor loading. The problem in estimation of maximum likelihood is Undefined function ‘statsfminbx’ for input arguments of type ‘cell’. What is statsfminbx indicate here?The maximum likelihood estimation of factor loading. The problem in estimation of maximum likelihood is Undefined function ‘statsfminbx’ for input arguments of type ‘cell’. What is statsfminbx indicate here? The maximum likelihood estimation of factor loading. The problem in estimation of maximum likelihood is Undefined function ‘statsfminbx’ for input arguments of type ‘cell’. What is statsfminbx indicate here? factoran, statsfminbx, loglike., statistics, image processing MATLAB Answers — New Questions
Explain the below Kmeans code.
Extract from http://www.mathworks.in/matlabcentral/fileexchange/24616-kmeans-clustering/content/litekmeans/litekmeans.m, below
E = sparse(1:n,label,1,n,k,n); % transform label into indicator matrix
m = X*(E*spdiags(1./sum(E,1)’,0,k,k)); % compute m of each cluster
[~,label] = max(bsxfun(@minus,m’*X,dot(m,m,1)’/2),[],1); % assign samples to the
Can you please explain the above code?Extract from http://www.mathworks.in/matlabcentral/fileexchange/24616-kmeans-clustering/content/litekmeans/litekmeans.m, below
E = sparse(1:n,label,1,n,k,n); % transform label into indicator matrix
m = X*(E*spdiags(1./sum(E,1)’,0,k,k)); % compute m of each cluster
[~,label] = max(bsxfun(@minus,m’*X,dot(m,m,1)’/2),[],1); % assign samples to the
Can you please explain the above code? Extract from http://www.mathworks.in/matlabcentral/fileexchange/24616-kmeans-clustering/content/litekmeans/litekmeans.m, below
E = sparse(1:n,label,1,n,k,n); % transform label into indicator matrix
m = X*(E*spdiags(1./sum(E,1)’,0,k,k)); % compute m of each cluster
[~,label] = max(bsxfun(@minus,m’*X,dot(m,m,1)’/2),[],1); % assign samples to the
Can you please explain the above code? kmeans MATLAB Answers — New Questions