Tag Archives: matlab
Matlab 2024a creates “Downloads” folder automatically when start up
I installed matlab 2024a in CentOS Stream 9. It creates a folder named "Downloads" at my home directory everytime when I launch it. I really don’t like this feature. In the previous version, it can be solved by ‘userpath /path/prefer’. But it didn’t work for 2024a. Is there a way to avoid creating "Downloads"?I installed matlab 2024a in CentOS Stream 9. It creates a folder named "Downloads" at my home directory everytime when I launch it. I really don’t like this feature. In the previous version, it can be solved by ‘userpath /path/prefer’. But it didn’t work for 2024a. Is there a way to avoid creating "Downloads"? I installed matlab 2024a in CentOS Stream 9. It creates a folder named "Downloads" at my home directory everytime when I launch it. I really don’t like this feature. In the previous version, it can be solved by ‘userpath /path/prefer’. But it didn’t work for 2024a. Is there a way to avoid creating "Downloads"? matlab startup MATLAB Answers — New Questions
calling function from separate document for fitting
Hi all, I am working on this curve fitting project and I am trying out different methods to optimise the run time. One of the methods I am trying involes having 2 seperate scripts, with one script containing the function used for fitting and curve fitting (call this script 1), and the other script containing codes to load the data and process the data (call this script 2). However, when I try to call script 1 from 2, I get a ton of error messages. Could I please ask why is this the problem? Thank you! My codes are attached below:
tic
%% Preparation
clc; clear
format short
TAdata = readmatrix("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
MBdata = readmatrix("carrier temp.xlsx");
P = load("Steady_State_Parameter_Values.mat");
Function = ‘Transient_Absorption’;
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = TAdata(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = TAdata(1, :);
delay_T = MBdata(:, 2);
carrier_T = MBdata(:, 3);
% Data for fitting
min_E = 1.5;
max_E = 2.0;
Range_E = E >= min_E & E <= max_E;
Range_W = Wavelength >= (h*c)/(max_E*10^-9) & Wavelength <= (h*c)/(min_E*10^-9);
E_p = E(Range_E); % selected probe energies
for n = 1:length(carrier_T)
a(1, n) = find(delay_T(n) == delay_t);
data_new2 = TAdata(Range_W, a);
end
%% Data for fitting and calling fitting function & solver
for i = 1:length(delay_T)
p = P.p;
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
deltaAbs = data_new2(:, i);
lb = [0, 0, 0, 0.3, 0, 0]; ub = [20, 0.05, 0.05, 2, 2, 1];
x0 = [1.6244, 0.0346, 0.03, 1.5139, 1, 0.3];
carrierT = carrier_T(i);
[x] = TA_fitting_function(A1, A2, Eg, Eb, R, g, x0,x,carrierT,E_p,deltaAbs,lb,ub,i,LegendText, Function);
end
%% Table of parameter values
time_delay = [‘0.5 ps’; ‘1.0 ps’; ‘2.0 ps’; ‘4.0 ps’];
Eg_prime = x(:, 1);
Eb_prime = x(:, 2);
g_prime = x(:, 3);
Ef_q = x(:, 4);
f1 = x(:, 5);
f2 = x(:, 6);
T = table(time_delay, Eg_prime, Eb_prime, g_prime, Ef_q, f1, f2);
disp(T)
tocHi all, I am working on this curve fitting project and I am trying out different methods to optimise the run time. One of the methods I am trying involes having 2 seperate scripts, with one script containing the function used for fitting and curve fitting (call this script 1), and the other script containing codes to load the data and process the data (call this script 2). However, when I try to call script 1 from 2, I get a ton of error messages. Could I please ask why is this the problem? Thank you! My codes are attached below:
tic
%% Preparation
clc; clear
format short
TAdata = readmatrix("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
MBdata = readmatrix("carrier temp.xlsx");
P = load("Steady_State_Parameter_Values.mat");
Function = ‘Transient_Absorption’;
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = TAdata(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = TAdata(1, :);
delay_T = MBdata(:, 2);
carrier_T = MBdata(:, 3);
% Data for fitting
min_E = 1.5;
max_E = 2.0;
Range_E = E >= min_E & E <= max_E;
Range_W = Wavelength >= (h*c)/(max_E*10^-9) & Wavelength <= (h*c)/(min_E*10^-9);
E_p = E(Range_E); % selected probe energies
for n = 1:length(carrier_T)
a(1, n) = find(delay_T(n) == delay_t);
data_new2 = TAdata(Range_W, a);
end
%% Data for fitting and calling fitting function & solver
for i = 1:length(delay_T)
p = P.p;
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
deltaAbs = data_new2(:, i);
lb = [0, 0, 0, 0.3, 0, 0]; ub = [20, 0.05, 0.05, 2, 2, 1];
x0 = [1.6244, 0.0346, 0.03, 1.5139, 1, 0.3];
carrierT = carrier_T(i);
[x] = TA_fitting_function(A1, A2, Eg, Eb, R, g, x0,x,carrierT,E_p,deltaAbs,lb,ub,i,LegendText, Function);
end
%% Table of parameter values
time_delay = [‘0.5 ps’; ‘1.0 ps’; ‘2.0 ps’; ‘4.0 ps’];
Eg_prime = x(:, 1);
Eb_prime = x(:, 2);
g_prime = x(:, 3);
Ef_q = x(:, 4);
f1 = x(:, 5);
f2 = x(:, 6);
T = table(time_delay, Eg_prime, Eb_prime, g_prime, Ef_q, f1, f2);
disp(T)
toc Hi all, I am working on this curve fitting project and I am trying out different methods to optimise the run time. One of the methods I am trying involes having 2 seperate scripts, with one script containing the function used for fitting and curve fitting (call this script 1), and the other script containing codes to load the data and process the data (call this script 2). However, when I try to call script 1 from 2, I get a ton of error messages. Could I please ask why is this the problem? Thank you! My codes are attached below:
tic
%% Preparation
clc; clear
format short
TAdata = readmatrix("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
MBdata = readmatrix("carrier temp.xlsx");
P = load("Steady_State_Parameter_Values.mat");
Function = ‘Transient_Absorption’;
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = TAdata(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = TAdata(1, :);
delay_T = MBdata(:, 2);
carrier_T = MBdata(:, 3);
% Data for fitting
min_E = 1.5;
max_E = 2.0;
Range_E = E >= min_E & E <= max_E;
Range_W = Wavelength >= (h*c)/(max_E*10^-9) & Wavelength <= (h*c)/(min_E*10^-9);
E_p = E(Range_E); % selected probe energies
for n = 1:length(carrier_T)
a(1, n) = find(delay_T(n) == delay_t);
data_new2 = TAdata(Range_W, a);
end
%% Data for fitting and calling fitting function & solver
for i = 1:length(delay_T)
p = P.p;
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
deltaAbs = data_new2(:, i);
lb = [0, 0, 0, 0.3, 0, 0]; ub = [20, 0.05, 0.05, 2, 2, 1];
x0 = [1.6244, 0.0346, 0.03, 1.5139, 1, 0.3];
carrierT = carrier_T(i);
[x] = TA_fitting_function(A1, A2, Eg, Eb, R, g, x0,x,carrierT,E_p,deltaAbs,lb,ub,i,LegendText, Function);
end
%% Table of parameter values
time_delay = [‘0.5 ps’; ‘1.0 ps’; ‘2.0 ps’; ‘4.0 ps’];
Eg_prime = x(:, 1);
Eb_prime = x(:, 2);
g_prime = x(:, 3);
Ef_q = x(:, 4);
f1 = x(:, 5);
f2 = x(:, 6);
T = table(time_delay, Eg_prime, Eb_prime, g_prime, Ef_q, f1, f2);
disp(T)
toc curve fitting MATLAB Answers — New Questions
how to add custom header to each file ?
How can i add custom header to each file in my project ? details like author, data created, short description about code etc.How can i add custom header to each file in my project ? details like author, data created, short description about code etc. How can i add custom header to each file in my project ? details like author, data created, short description about code etc. header MATLAB Answers — New Questions
Why is my coeff variable blank when I run PCA?
So I would like to conduct PCA on a dataset I have that is of sample size 23 and feature size 813 (nxp = 23×813). However, when I run the pca function, the coeff variable returned is blank. why is this the case? I am aware my sample size: feature size ratio is very low, but the function returned a 813×22 coefficient matrix when I ran it on my data before I processed it (transformed nonnormally distributed data & feature scaling) so I know it is not because of unsuitable data size.
I have attached a copy of the data I am trying to use if anyone is able to help; thanks!
[coeff, ~, latent] = pca(deltaEBC);
UPDATE: I was feature scaling by taking feature X, subtracting the mean of X, and dividing by the standard deviation of X. I changed this to simply subtracting the mean and not dividing by the std, and now the pca function does return a 813 x 22 coeff I was looking for. I just don’t know why?So I would like to conduct PCA on a dataset I have that is of sample size 23 and feature size 813 (nxp = 23×813). However, when I run the pca function, the coeff variable returned is blank. why is this the case? I am aware my sample size: feature size ratio is very low, but the function returned a 813×22 coefficient matrix when I ran it on my data before I processed it (transformed nonnormally distributed data & feature scaling) so I know it is not because of unsuitable data size.
I have attached a copy of the data I am trying to use if anyone is able to help; thanks!
[coeff, ~, latent] = pca(deltaEBC);
UPDATE: I was feature scaling by taking feature X, subtracting the mean of X, and dividing by the standard deviation of X. I changed this to simply subtracting the mean and not dividing by the std, and now the pca function does return a 813 x 22 coeff I was looking for. I just don’t know why? So I would like to conduct PCA on a dataset I have that is of sample size 23 and feature size 813 (nxp = 23×813). However, when I run the pca function, the coeff variable returned is blank. why is this the case? I am aware my sample size: feature size ratio is very low, but the function returned a 813×22 coefficient matrix when I ran it on my data before I processed it (transformed nonnormally distributed data & feature scaling) so I know it is not because of unsuitable data size.
I have attached a copy of the data I am trying to use if anyone is able to help; thanks!
[coeff, ~, latent] = pca(deltaEBC);
UPDATE: I was feature scaling by taking feature X, subtracting the mean of X, and dividing by the standard deviation of X. I changed this to simply subtracting the mean and not dividing by the std, and now the pca function does return a 813 x 22 coeff I was looking for. I just don’t know why? pca MATLAB Answers — New Questions
Which regressors do the parameter estimates belong to returned by ‘nlarx’?
I estimate a model using ‘nlarx’ from data like this
mdl = nlarx(data,sys);
Then, in the ‘mdl’ object has a field
mdl.Report.Parameters.ParVector
which lists the parameter estimates in a single column vector. Now, i see that the number of parameters estimates equal the number of ‘true’s in
sys.RegressorUsage
which is a table, however, I do not find information anywhere, in the Matlab documentation or on the internet, which individual instant of ‘true’ in sys.RegressorUsage, i.e., which individual regressors, belongs to which entry of mdl.Report.Parameters.ParVector.
Furthermore, i would like to ask where i can find p-values or standard errors for each of these parameter estimates.
Any help would be much appreciated!I estimate a model using ‘nlarx’ from data like this
mdl = nlarx(data,sys);
Then, in the ‘mdl’ object has a field
mdl.Report.Parameters.ParVector
which lists the parameter estimates in a single column vector. Now, i see that the number of parameters estimates equal the number of ‘true’s in
sys.RegressorUsage
which is a table, however, I do not find information anywhere, in the Matlab documentation or on the internet, which individual instant of ‘true’ in sys.RegressorUsage, i.e., which individual regressors, belongs to which entry of mdl.Report.Parameters.ParVector.
Furthermore, i would like to ask where i can find p-values or standard errors for each of these parameter estimates.
Any help would be much appreciated! I estimate a model using ‘nlarx’ from data like this
mdl = nlarx(data,sys);
Then, in the ‘mdl’ object has a field
mdl.Report.Parameters.ParVector
which lists the parameter estimates in a single column vector. Now, i see that the number of parameters estimates equal the number of ‘true’s in
sys.RegressorUsage
which is a table, however, I do not find information anywhere, in the Matlab documentation or on the internet, which individual instant of ‘true’ in sys.RegressorUsage, i.e., which individual regressors, belongs to which entry of mdl.Report.Parameters.ParVector.
Furthermore, i would like to ask where i can find p-values or standard errors for each of these parameter estimates.
Any help would be much appreciated! nlarx, regression, nonlinear model, system identification MATLAB Answers — New Questions
How to Install Signal Builder in Matlab 2023b
I have some scripts that directly create Signal Builder. How to solve the problem of signal builder being invalid after running the script in Matlab 2023b?I have some scripts that directly create Signal Builder. How to solve the problem of signal builder being invalid after running the script in Matlab 2023b? I have some scripts that directly create Signal Builder. How to solve the problem of signal builder being invalid after running the script in Matlab 2023b? signal builder MATLAB Answers — New Questions
Which sample time for simulating discrete Stepper Motor model (FOC Control)?
Is there an ideal sample time or rule of thumb for simulating discrete time motor models with field oriented control?
I’ve been working on a Motor Control Project, controlling a Stepper Motor with field oriented control. I oriented my model towards the motor control blockset. The Stepper Motor is a block build by myself (discrete time). My Current Control loop is working with 16kHz. My Motor is simulated every 160kHz, so 10 times faster, as the control loop (The factor of 10 is used in some motor control blockset examples). With the goal to get faster simulation results, i tried to reduce the sample time of my motor model. The strange thing is, that i’ve got different control behaviour. Here are some pictures of my motor speed response (speed is ramped) with different motor sample times.
Motor Sample Time: 160kHz (10 times faster than current control)
Motor Sample Time: 80kHz (5 times faster than current control)
Motor Sample Time: 32kHz (2 times faster than current control)Is there an ideal sample time or rule of thumb for simulating discrete time motor models with field oriented control?
I’ve been working on a Motor Control Project, controlling a Stepper Motor with field oriented control. I oriented my model towards the motor control blockset. The Stepper Motor is a block build by myself (discrete time). My Current Control loop is working with 16kHz. My Motor is simulated every 160kHz, so 10 times faster, as the control loop (The factor of 10 is used in some motor control blockset examples). With the goal to get faster simulation results, i tried to reduce the sample time of my motor model. The strange thing is, that i’ve got different control behaviour. Here are some pictures of my motor speed response (speed is ramped) with different motor sample times.
Motor Sample Time: 160kHz (10 times faster than current control)
Motor Sample Time: 80kHz (5 times faster than current control)
Motor Sample Time: 32kHz (2 times faster than current control) Is there an ideal sample time or rule of thumb for simulating discrete time motor models with field oriented control?
I’ve been working on a Motor Control Project, controlling a Stepper Motor with field oriented control. I oriented my model towards the motor control blockset. The Stepper Motor is a block build by myself (discrete time). My Current Control loop is working with 16kHz. My Motor is simulated every 160kHz, so 10 times faster, as the control loop (The factor of 10 is used in some motor control blockset examples). With the goal to get faster simulation results, i tried to reduce the sample time of my motor model. The strange thing is, that i’ve got different control behaviour. Here are some pictures of my motor speed response (speed is ramped) with different motor sample times.
Motor Sample Time: 160kHz (10 times faster than current control)
Motor Sample Time: 80kHz (5 times faster than current control)
Motor Sample Time: 32kHz (2 times faster than current control) electric_motor_control, field oriented control, motor control blockset, simulink, simulation, stepper motor MATLAB Answers — New Questions
How to Make the Ports and Internal Variables of a FMU Block, Visible or Invisible?
I am using Matlab 2023a to insert an FMU block into my Simulink model with the following two lines of code:
>> addpath(‘path/of/the/fmu/file’)
>> fmu_block = add_block(‘simulink_extras/FMU Import/FMU’, ‘MyModel/MyFMU’, ‘FMUName’, ‘fmu_file.fmu’);
The FMU block is successfully inserted into my model, and everything is currently working well. When I double-click on the FMU block, I can see options to enable or disable the visibility of each output port and internal variable:
Now, I’m wondering how I can use a Matlab script to control the visibility of output ports or variables. I’ve already attempted to retrieve port information using get_param(…), such as this:
port_name = get_param(‘Model/FMU/1’, ‘Name’);
But unfortunately, Matlab gives me this error:
Invalid Simulink object name: ‘Model/FMU/1’.
Caused by:
‘FMU’ is not a SubSystem block.
Therefore, the question remains: How can I retrieve or modify the visibility parameter of the ports and variables within an FMU block? I would appreciate any assistance anyone can provide.I am using Matlab 2023a to insert an FMU block into my Simulink model with the following two lines of code:
>> addpath(‘path/of/the/fmu/file’)
>> fmu_block = add_block(‘simulink_extras/FMU Import/FMU’, ‘MyModel/MyFMU’, ‘FMUName’, ‘fmu_file.fmu’);
The FMU block is successfully inserted into my model, and everything is currently working well. When I double-click on the FMU block, I can see options to enable or disable the visibility of each output port and internal variable:
Now, I’m wondering how I can use a Matlab script to control the visibility of output ports or variables. I’ve already attempted to retrieve port information using get_param(…), such as this:
port_name = get_param(‘Model/FMU/1’, ‘Name’);
But unfortunately, Matlab gives me this error:
Invalid Simulink object name: ‘Model/FMU/1’.
Caused by:
‘FMU’ is not a SubSystem block.
Therefore, the question remains: How can I retrieve or modify the visibility parameter of the ports and variables within an FMU block? I would appreciate any assistance anyone can provide. I am using Matlab 2023a to insert an FMU block into my Simulink model with the following two lines of code:
>> addpath(‘path/of/the/fmu/file’)
>> fmu_block = add_block(‘simulink_extras/FMU Import/FMU’, ‘MyModel/MyFMU’, ‘FMUName’, ‘fmu_file.fmu’);
The FMU block is successfully inserted into my model, and everything is currently working well. When I double-click on the FMU block, I can see options to enable or disable the visibility of each output port and internal variable:
Now, I’m wondering how I can use a Matlab script to control the visibility of output ports or variables. I’ve already attempted to retrieve port information using get_param(…), such as this:
port_name = get_param(‘Model/FMU/1’, ‘Name’);
But unfortunately, Matlab gives me this error:
Invalid Simulink object name: ‘Model/FMU/1’.
Caused by:
‘FMU’ is not a SubSystem block.
Therefore, the question remains: How can I retrieve or modify the visibility parameter of the ports and variables within an FMU block? I would appreciate any assistance anyone can provide. fmu, visibility, set_param MATLAB Answers — New Questions
Folders not found when started newly installed MATLAB R2024a
After update to MATLAB R2024a, I enountered some error messages in the command window saying some folders or files not existed, please refer to attached image. I can’t do anything now. Please advise how I can resolve it.
Thank you very much!After update to MATLAB R2024a, I enountered some error messages in the command window saying some folders or files not existed, please refer to attached image. I can’t do anything now. Please advise how I can resolve it.
Thank you very much! After update to MATLAB R2024a, I enountered some error messages in the command window saying some folders or files not existed, please refer to attached image. I can’t do anything now. Please advise how I can resolve it.
Thank you very much! r2024a, installation MATLAB Answers — New Questions
Debug mode for RL agent networks
Is there any way to enter debug mode, to see what is happening inside the RL agent nets while training is running?
Some of my layers output NaN and I would like to know which one. I would also like to monitor to outputs of each layer.
Thanks in advance!
NicolasIs there any way to enter debug mode, to see what is happening inside the RL agent nets while training is running?
Some of my layers output NaN and I would like to know which one. I would also like to monitor to outputs of each layer.
Thanks in advance!
Nicolas Is there any way to enter debug mode, to see what is happening inside the RL agent nets while training is running?
Some of my layers output NaN and I would like to know which one. I would also like to monitor to outputs of each layer.
Thanks in advance!
Nicolas reinforcement learning, matlab, deep learning, debug mode MATLAB Answers — New Questions
Combining datasets using Geo data/ How to retain data values using ‘imfuse’
Hi,
I am trying to imfuse these two datasets Data1 & Data2 (data type Double) with R1 and R2 (R1 and R2 are spatial coordinates data & pixel sizes etc.). However, the end product ‘AB’ is changing the data type to uint 8, and this change of data type is also affecting the values in dataset (changed). I have checked the documentation but the output of ‘Imfuse’ is ‘uint 8’.
I need some advise, How can I embed these two datasets using geo data, which dont alter its data values. If there is some other function or technique to do it. Kindly advise.
AB=imfuse(data2,R2,data1,R1,’blend’,’Scaling’,’joint’);
figure;
imshow(AB);
I have attached the files.Hi,
I am trying to imfuse these two datasets Data1 & Data2 (data type Double) with R1 and R2 (R1 and R2 are spatial coordinates data & pixel sizes etc.). However, the end product ‘AB’ is changing the data type to uint 8, and this change of data type is also affecting the values in dataset (changed). I have checked the documentation but the output of ‘Imfuse’ is ‘uint 8’.
I need some advise, How can I embed these two datasets using geo data, which dont alter its data values. If there is some other function or technique to do it. Kindly advise.
AB=imfuse(data2,R2,data1,R1,’blend’,’Scaling’,’joint’);
figure;
imshow(AB);
I have attached the files. Hi,
I am trying to imfuse these two datasets Data1 & Data2 (data type Double) with R1 and R2 (R1 and R2 are spatial coordinates data & pixel sizes etc.). However, the end product ‘AB’ is changing the data type to uint 8, and this change of data type is also affecting the values in dataset (changed). I have checked the documentation but the output of ‘Imfuse’ is ‘uint 8’.
I need some advise, How can I embed these two datasets using geo data, which dont alter its data values. If there is some other function or technique to do it. Kindly advise.
AB=imfuse(data2,R2,data1,R1,’blend’,’Scaling’,’joint’);
figure;
imshow(AB);
I have attached the files. image processing, digital image processing, data MATLAB Answers — New Questions
Speeding up numerical gradient of tensor with FFTs
I have a gradient problem that involves the following function: adding a phase to each column in a matrix and computing the FFT of each column, and aggregating all FFTs into a new matrix.
My brute-force numerical gradient is adding a small phase to each column, iteratively, and then computing the loss by comparing it with some known matrix. currX is the current guess of phases, Ts2pHH is the matrix to whose columns these phases are added, and the function is computing by taking a sum along 2 dimensions of the intensity and then adding it up.
I want to know if this can be done more efficiently, because for my matrix size (~1000×1000) this takes around 2 minutes, which is very slow.
My code is shown below:
for k = 1:length(currX)
currX_perturbed = currX;
currX_perturbed(k) = currX_perturbed(k) + epsilon;
phases_perturbed = exp(1i * [0, currX_perturbed]);
Tcorr_perturbed = Ts2pHH .* phases_perturbed;
TcorrFFT_perturbed = fftshift(fft(fft(fft(fft(reshape(Tcorr_perturbed, [Npx, Npx, Nin, Nin]), [], 3), [], 4), [], 1), [], 2));
inputFreq_perturbed = squeeze(sum(sum(abs(TcorrFFT_perturbed).^2, 1), 2));
gradient(k) = gradient(k) + (-sum(inputFreq_perturbed .* support, ‘all’) – loss) / epsilon;
endI have a gradient problem that involves the following function: adding a phase to each column in a matrix and computing the FFT of each column, and aggregating all FFTs into a new matrix.
My brute-force numerical gradient is adding a small phase to each column, iteratively, and then computing the loss by comparing it with some known matrix. currX is the current guess of phases, Ts2pHH is the matrix to whose columns these phases are added, and the function is computing by taking a sum along 2 dimensions of the intensity and then adding it up.
I want to know if this can be done more efficiently, because for my matrix size (~1000×1000) this takes around 2 minutes, which is very slow.
My code is shown below:
for k = 1:length(currX)
currX_perturbed = currX;
currX_perturbed(k) = currX_perturbed(k) + epsilon;
phases_perturbed = exp(1i * [0, currX_perturbed]);
Tcorr_perturbed = Ts2pHH .* phases_perturbed;
TcorrFFT_perturbed = fftshift(fft(fft(fft(fft(reshape(Tcorr_perturbed, [Npx, Npx, Nin, Nin]), [], 3), [], 4), [], 1), [], 2));
inputFreq_perturbed = squeeze(sum(sum(abs(TcorrFFT_perturbed).^2, 1), 2));
gradient(k) = gradient(k) + (-sum(inputFreq_perturbed .* support, ‘all’) – loss) / epsilon;
end I have a gradient problem that involves the following function: adding a phase to each column in a matrix and computing the FFT of each column, and aggregating all FFTs into a new matrix.
My brute-force numerical gradient is adding a small phase to each column, iteratively, and then computing the loss by comparing it with some known matrix. currX is the current guess of phases, Ts2pHH is the matrix to whose columns these phases are added, and the function is computing by taking a sum along 2 dimensions of the intensity and then adding it up.
I want to know if this can be done more efficiently, because for my matrix size (~1000×1000) this takes around 2 minutes, which is very slow.
My code is shown below:
for k = 1:length(currX)
currX_perturbed = currX;
currX_perturbed(k) = currX_perturbed(k) + epsilon;
phases_perturbed = exp(1i * [0, currX_perturbed]);
Tcorr_perturbed = Ts2pHH .* phases_perturbed;
TcorrFFT_perturbed = fftshift(fft(fft(fft(fft(reshape(Tcorr_perturbed, [Npx, Npx, Nin, Nin]), [], 3), [], 4), [], 1), [], 2));
inputFreq_perturbed = squeeze(sum(sum(abs(TcorrFFT_perturbed).^2, 1), 2));
gradient(k) = gradient(k) + (-sum(inputFreq_perturbed .* support, ‘all’) – loss) / epsilon;
end gradient, optimization, speed, fft, for loop, matrix, loop, iteration MATLAB Answers — New Questions
Feature Fusion code to fuse two feature space
Anyone, can you share the code for Attentional Feature Fusion (AFF) and iterative AFF.?Anyone, can you share the code for Attentional Feature Fusion (AFF) and iterative AFF.? Anyone, can you share the code for Attentional Feature Fusion (AFF) and iterative AFF.? feature fusion MATLAB Answers — New Questions
Hi i created a matfile of hourly temperature 334*334*2928 . how i can convert the .mat file to Tif file ?
attached the screen shotattached the screen shot attached the screen shot #matfile conversion #tifformat MATLAB Answers — New Questions
Assenza comando Estimate in estimate transfer function
Post Content Post Content system identification, estimate transfer function MATLAB Answers — New Questions
Extract data from fileDatastore and cell
read(fds)
ans =
struct with fields:
data: {178093×3 cell}
Cell data is somthing like that
{1×1×9 double} {10×20×3 single} {[0.4343]}
How can extract all rows and but 1 and 3 number columns such as only {1×1×9 double} {[0.4343]} using fds.data ?read(fds)
ans =
struct with fields:
data: {178093×3 cell}
Cell data is somthing like that
{1×1×9 double} {10×20×3 single} {[0.4343]}
How can extract all rows and but 1 and 3 number columns such as only {1×1×9 double} {[0.4343]} using fds.data ? read(fds)
ans =
struct with fields:
data: {178093×3 cell}
Cell data is somthing like that
{1×1×9 double} {10×20×3 single} {[0.4343]}
How can extract all rows and but 1 and 3 number columns such as only {1×1×9 double} {[0.4343]} using fds.data ? filedatastore, cell MATLAB Answers — New Questions
why do I get the error ”Attempt to execute SCRIPT edge as a function:”?
I want to edge a gray scale image and I receive this error: ”Attempt to execute SCRIPT edge as a function:” can any one help me?I want to edge a gray scale image and I receive this error: ”Attempt to execute SCRIPT edge as a function:” can any one help me? I want to edge a gray scale image and I receive this error: ”Attempt to execute SCRIPT edge as a function:” can any one help me? image processing MATLAB Answers — New Questions
Issue When Update to MATLAB R2024a
When I tried to update to R2024a, I got the popup to agree the license agreement. But I can’t click either "Yes" or "No", neither "Next" or "Cancel" button, like the screen shot attached below. I tried change screen resolution but it doesn’t resolve the issue. Any suggestions on how to solve it?
Many thanks!When I tried to update to R2024a, I got the popup to agree the license agreement. But I can’t click either "Yes" or "No", neither "Next" or "Cancel" button, like the screen shot attached below. I tried change screen resolution but it doesn’t resolve the issue. Any suggestions on how to solve it?
Many thanks! When I tried to update to R2024a, I got the popup to agree the license agreement. But I can’t click either "Yes" or "No", neither "Next" or "Cancel" button, like the screen shot attached below. I tried change screen resolution but it doesn’t resolve the issue. Any suggestions on how to solve it?
Many thanks! r2024a, update MATLAB Answers — New Questions
Error running ‘h2f_175_S2_sil_plant_model’ on target computer: Timed out waiting for External mode connect to complete.
Hello
I am running Fuel cell plant model on speedgoat target machine, while running in getting this single error <Error running ‘h2f_175_S2_sil_plant_model’ on target computer: Timed out waiting for External mode connect to complete.>, while model uploaded to target machine but simulation not starting .
Thanks in advancedHello
I am running Fuel cell plant model on speedgoat target machine, while running in getting this single error <Error running ‘h2f_175_S2_sil_plant_model’ on target computer: Timed out waiting for External mode connect to complete.>, while model uploaded to target machine but simulation not starting .
Thanks in advanced Hello
I am running Fuel cell plant model on speedgoat target machine, while running in getting this single error <Error running ‘h2f_175_S2_sil_plant_model’ on target computer: Timed out waiting for External mode connect to complete.>, while model uploaded to target machine but simulation not starting .
Thanks in advanced thingspeak, realtime, matlab, simulink, targetmachine MATLAB Answers — New Questions
GUIDE code from pre 2015 need to access the button press function and “programatically press the button” from a different m file
Hey All
As the title suggests, I am dealing with a GUIDE file from a long time ago and I need to have it running and while its running I want to be able to access one of the functions called SaveSpectrumPlotButton_Callback() on line 1933
I have not been able to find how to access it from a different file or even create an output that I could maybe access in order to activate that button. I have shared the m file below
Any help would be much appreciated/Hey All
As the title suggests, I am dealing with a GUIDE file from a long time ago and I need to have it running and while its running I want to be able to access one of the functions called SaveSpectrumPlotButton_Callback() on line 1933
I have not been able to find how to access it from a different file or even create an output that I could maybe access in order to activate that button. I have shared the m file below
Any help would be much appreciated/ Hey All
As the title suggests, I am dealing with a GUIDE file from a long time ago and I need to have it running and while its running I want to be able to access one of the functions called SaveSpectrumPlotButton_Callback() on line 1933
I have not been able to find how to access it from a different file or even create an output that I could maybe access in order to activate that button. I have shared the m file below
Any help would be much appreciated/ guide, serial communication, functions MATLAB Answers — New Questions