Category: Matlab
Category Archives: Matlab
artificial neural network bias
Hi all,
I have developed an artificial neural network with a single hidden layer. The purpose of this is to predict as a probability when a cliff will fail given wave, sea level and precipitation data. To do this I have used the ‘fitnet’ function. However, I am still very new to neural networks and dont fully understand the parameters behind them. Currently, the network is reproducing the test data ok ish however it is struggling to produce the validation data. This is because I have input the cliff failures as a binary column which has cliff failures as 1 and no failures as 0. There are approximately 30 failures which occur across 262 days. The issue is that the network is heavily biased towards reproducing non-failures and therefore when it attempts to predict the validation data does not predict any failures. This means the network ouputs more zeros than required since the training data is mostly zeros since most days experience no cliff failure. I am aware that there is potential to use a grid search to optimise the hyper parameters but I am unsure how to do this. How can I adjust the bias to reproduce more representative results.
Any help would be greatly appreciated.Hi all,
I have developed an artificial neural network with a single hidden layer. The purpose of this is to predict as a probability when a cliff will fail given wave, sea level and precipitation data. To do this I have used the ‘fitnet’ function. However, I am still very new to neural networks and dont fully understand the parameters behind them. Currently, the network is reproducing the test data ok ish however it is struggling to produce the validation data. This is because I have input the cliff failures as a binary column which has cliff failures as 1 and no failures as 0. There are approximately 30 failures which occur across 262 days. The issue is that the network is heavily biased towards reproducing non-failures and therefore when it attempts to predict the validation data does not predict any failures. This means the network ouputs more zeros than required since the training data is mostly zeros since most days experience no cliff failure. I am aware that there is potential to use a grid search to optimise the hyper parameters but I am unsure how to do this. How can I adjust the bias to reproduce more representative results.
Any help would be greatly appreciated. Hi all,
I have developed an artificial neural network with a single hidden layer. The purpose of this is to predict as a probability when a cliff will fail given wave, sea level and precipitation data. To do this I have used the ‘fitnet’ function. However, I am still very new to neural networks and dont fully understand the parameters behind them. Currently, the network is reproducing the test data ok ish however it is struggling to produce the validation data. This is because I have input the cliff failures as a binary column which has cliff failures as 1 and no failures as 0. There are approximately 30 failures which occur across 262 days. The issue is that the network is heavily biased towards reproducing non-failures and therefore when it attempts to predict the validation data does not predict any failures. This means the network ouputs more zeros than required since the training data is mostly zeros since most days experience no cliff failure. I am aware that there is potential to use a grid search to optimise the hyper parameters but I am unsure how to do this. How can I adjust the bias to reproduce more representative results.
Any help would be greatly appreciated. neural network, neural networks, ai, machine learning, binary, fitnet, bias, deep learning MATLAB Answers — New Questions
How do structures work?
How do structures work? I’ve been trying a smoewhat big struct file but the workspace cannot seem to be able to find the values of the structure (the values of the fields are missing). Here is the code. Please help me I do not know what to do.
Default_GP = struct ( …%
…% — Connection Properties —
…%
‘Platform’, "B200", …
‘SerialNum’, "321E19C", …
…%
…% — Configuration Propreties —
…%
…% Frequency
…%
‘CenterFrequency’, 101e6, …
‘FrequencyCorrection’, 0, … //LO offset
‘FrequencyStepsString’ ,{{‘1 Hz’,’10 Hz’,’100 Hz’,’1 kHz’,’10 kHz’,’100 kHz’,’1 MHz’,’10 MHz’,’100 MHz’}}, …
‘AllFrequencySteps’,[1,10,100,1e3,10e3,100e3,1e6,10e6,100e6],…
‘FrequencyStep’,100e3,…
…%
…% Reciever Gain
…%
‘RecieverGain’, 0,… % 76 dB – max reciver gain
…
…
‘AllPPSSources’, {{"Internal", "External", "GPSDO"}},…
‘PPSSource’, "Internal",…
‘AllClockSources’, {{"Internal", "External", "GPSDO"}},…
‘ClockSource’, "Internal",…
…%
…% Output
…%
‘AllSampleRates’, {},… % range of sample rates 5MHz – 61.44MHz
‘SampleRateSteps’, {{‘0.1 MHz’, ‘1 MHz’,’10 MHz’}},…
‘AllSampleRateSteps’, [0.1e6, 1e6, 10e6],…
‘SampleRate’, 32e6,… % Master Clock Rate
…
‘TransportDataTypeStrings’, {{"int16", "int8"}},…
‘TransportDataType’, "int16",…
‘OutputDataTypeString’, {{"int16", "int18", "single", "double"}},…
‘OutputDataType’, "double",…
…
‘AllSamplesPerFrameString’,{{‘4096′,’8192′,’16384′,’32768′,’65536′,’131072′,’262144’}},…
‘AllSamplesPerFrame’,[4096,8192,16384,32768,65536,131072,262144],…
‘SamplesPerFrame’,131072,…
…
‘EnableBurstMode’,false,… % Ensure a set of frames without overrun of USRP B200 output
‘NumFramesInBurst’,10,… % Number of frames in contiguous burstof USRP B200 output
…%
…% Baseband Decimation
…%
‘AllDecimationFactorsRanges’, {{‘[1, 128]’, ‘[128, 256]’, ‘[256-512]’}},…
‘DecimationMultiplesOf’, [1, 2, 4],…
‘DecimationFactor’, 1); % to be addedHow do structures work? I’ve been trying a smoewhat big struct file but the workspace cannot seem to be able to find the values of the structure (the values of the fields are missing). Here is the code. Please help me I do not know what to do.
Default_GP = struct ( …%
…% — Connection Properties —
…%
‘Platform’, "B200", …
‘SerialNum’, "321E19C", …
…%
…% — Configuration Propreties —
…%
…% Frequency
…%
‘CenterFrequency’, 101e6, …
‘FrequencyCorrection’, 0, … //LO offset
‘FrequencyStepsString’ ,{{‘1 Hz’,’10 Hz’,’100 Hz’,’1 kHz’,’10 kHz’,’100 kHz’,’1 MHz’,’10 MHz’,’100 MHz’}}, …
‘AllFrequencySteps’,[1,10,100,1e3,10e3,100e3,1e6,10e6,100e6],…
‘FrequencyStep’,100e3,…
…%
…% Reciever Gain
…%
‘RecieverGain’, 0,… % 76 dB – max reciver gain
…
…
‘AllPPSSources’, {{"Internal", "External", "GPSDO"}},…
‘PPSSource’, "Internal",…
‘AllClockSources’, {{"Internal", "External", "GPSDO"}},…
‘ClockSource’, "Internal",…
…%
…% Output
…%
‘AllSampleRates’, {},… % range of sample rates 5MHz – 61.44MHz
‘SampleRateSteps’, {{‘0.1 MHz’, ‘1 MHz’,’10 MHz’}},…
‘AllSampleRateSteps’, [0.1e6, 1e6, 10e6],…
‘SampleRate’, 32e6,… % Master Clock Rate
…
‘TransportDataTypeStrings’, {{"int16", "int8"}},…
‘TransportDataType’, "int16",…
‘OutputDataTypeString’, {{"int16", "int18", "single", "double"}},…
‘OutputDataType’, "double",…
…
‘AllSamplesPerFrameString’,{{‘4096′,’8192′,’16384′,’32768′,’65536′,’131072′,’262144’}},…
‘AllSamplesPerFrame’,[4096,8192,16384,32768,65536,131072,262144],…
‘SamplesPerFrame’,131072,…
…
‘EnableBurstMode’,false,… % Ensure a set of frames without overrun of USRP B200 output
‘NumFramesInBurst’,10,… % Number of frames in contiguous burstof USRP B200 output
…%
…% Baseband Decimation
…%
‘AllDecimationFactorsRanges’, {{‘[1, 128]’, ‘[128, 256]’, ‘[256-512]’}},…
‘DecimationMultiplesOf’, [1, 2, 4],…
‘DecimationFactor’, 1); % to be added How do structures work? I’ve been trying a smoewhat big struct file but the workspace cannot seem to be able to find the values of the structure (the values of the fields are missing). Here is the code. Please help me I do not know what to do.
Default_GP = struct ( …%
…% — Connection Properties —
…%
‘Platform’, "B200", …
‘SerialNum’, "321E19C", …
…%
…% — Configuration Propreties —
…%
…% Frequency
…%
‘CenterFrequency’, 101e6, …
‘FrequencyCorrection’, 0, … //LO offset
‘FrequencyStepsString’ ,{{‘1 Hz’,’10 Hz’,’100 Hz’,’1 kHz’,’10 kHz’,’100 kHz’,’1 MHz’,’10 MHz’,’100 MHz’}}, …
‘AllFrequencySteps’,[1,10,100,1e3,10e3,100e3,1e6,10e6,100e6],…
‘FrequencyStep’,100e3,…
…%
…% Reciever Gain
…%
‘RecieverGain’, 0,… % 76 dB – max reciver gain
…
…
‘AllPPSSources’, {{"Internal", "External", "GPSDO"}},…
‘PPSSource’, "Internal",…
‘AllClockSources’, {{"Internal", "External", "GPSDO"}},…
‘ClockSource’, "Internal",…
…%
…% Output
…%
‘AllSampleRates’, {},… % range of sample rates 5MHz – 61.44MHz
‘SampleRateSteps’, {{‘0.1 MHz’, ‘1 MHz’,’10 MHz’}},…
‘AllSampleRateSteps’, [0.1e6, 1e6, 10e6],…
‘SampleRate’, 32e6,… % Master Clock Rate
…
‘TransportDataTypeStrings’, {{"int16", "int8"}},…
‘TransportDataType’, "int16",…
‘OutputDataTypeString’, {{"int16", "int18", "single", "double"}},…
‘OutputDataType’, "double",…
…
‘AllSamplesPerFrameString’,{{‘4096′,’8192′,’16384′,’32768′,’65536′,’131072′,’262144’}},…
‘AllSamplesPerFrame’,[4096,8192,16384,32768,65536,131072,262144],…
‘SamplesPerFrame’,131072,…
…
‘EnableBurstMode’,false,… % Ensure a set of frames without overrun of USRP B200 output
‘NumFramesInBurst’,10,… % Number of frames in contiguous burstof USRP B200 output
…%
…% Baseband Decimation
…%
‘AllDecimationFactorsRanges’, {{‘[1, 128]’, ‘[128, 256]’, ‘[256-512]’}},…
‘DecimationMultiplesOf’, [1, 2, 4],…
‘DecimationFactor’, 1); % to be added structures, workspace, command MATLAB Answers — New Questions
plotting a 3d graph for a 3d table
I have a table and I want to plot a 3d graph for that.I have a table and I want to plot a 3d graph for that. I have a table and I want to plot a 3d graph for that. 3d plot MATLAB Answers — New Questions
Unable to open Unreal 5.1 Engine through Simulink after installation
I am in the process of migrating from Unreal Engine 4.27 to 5.1.1 for the purposes of simulation. I have downloaded R2024a and the new engine and followed this tutorial to put the MathWorks plugins in the directory (https://www.mathworks.com/help/vdynblks/ug/install-support-package-and-configure-environment.html) , however when I try and open an unreal project I get this error saying that it is unable to located some file from the Geospatial dll. The unreal engine then crashes and I am not sure what I did wrong. I still have 4.27 installed on my machine as well as old versions of MATLAB such as 23a and 23b.I am in the process of migrating from Unreal Engine 4.27 to 5.1.1 for the purposes of simulation. I have downloaded R2024a and the new engine and followed this tutorial to put the MathWorks plugins in the directory (https://www.mathworks.com/help/vdynblks/ug/install-support-package-and-configure-environment.html) , however when I try and open an unreal project I get this error saying that it is unable to located some file from the Geospatial dll. The unreal engine then crashes and I am not sure what I did wrong. I still have 4.27 installed on my machine as well as old versions of MATLAB such as 23a and 23b. I am in the process of migrating from Unreal Engine 4.27 to 5.1.1 for the purposes of simulation. I have downloaded R2024a and the new engine and followed this tutorial to put the MathWorks plugins in the directory (https://www.mathworks.com/help/vdynblks/ug/install-support-package-and-configure-environment.html) , however when I try and open an unreal project I get this error saying that it is unable to located some file from the Geospatial dll. The unreal engine then crashes and I am not sure what I did wrong. I still have 4.27 installed on my machine as well as old versions of MATLAB such as 23a and 23b. unreal engine, simulink MATLAB Answers — New Questions
3-phase programmable voltage source output
Hello,
I am using a 3 phase programmable voltage source with Amplitude(Vrm Ph-Ph) set to 600 V Phase set to 0 and Freq(Hz) set to 60. I am using a 3ph V-I mesaurement to read the voltages(phase-to-ground). The peak voltage reading from V-I measurement block is coming something around 489.9V. Can someone please explain why is it showing 489V?Hello,
I am using a 3 phase programmable voltage source with Amplitude(Vrm Ph-Ph) set to 600 V Phase set to 0 and Freq(Hz) set to 60. I am using a 3ph V-I mesaurement to read the voltages(phase-to-ground). The peak voltage reading from V-I measurement block is coming something around 489.9V. Can someone please explain why is it showing 489V? Hello,
I am using a 3 phase programmable voltage source with Amplitude(Vrm Ph-Ph) set to 600 V Phase set to 0 and Freq(Hz) set to 60. I am using a 3ph V-I mesaurement to read the voltages(phase-to-ground). The peak voltage reading from V-I measurement block is coming something around 489.9V. Can someone please explain why is it showing 489V? simscape MATLAB Answers — New Questions
Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 1-by-3. Error in pso_process_svc (line 31)
I am running a simulation on the location and sizing of svc on ieee 57 using pso algorithm.
It keeps displaying this error’
‘Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 1-by-3.
Error in pso_process_svc (line 31)
data_initial_pso_pop(indexloop,:) = DGsize_first_para;
Error in TOP_PSO (line 74)
[finalres,FINAL_SVC_LOCATION_SIZE,prop_best_datapso]=pso_process_svc(nbus,int_pop_size,…
please I need help in debugging this problemI am running a simulation on the location and sizing of svc on ieee 57 using pso algorithm.
It keeps displaying this error’
‘Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 1-by-3.
Error in pso_process_svc (line 31)
data_initial_pso_pop(indexloop,:) = DGsize_first_para;
Error in TOP_PSO (line 74)
[finalres,FINAL_SVC_LOCATION_SIZE,prop_best_datapso]=pso_process_svc(nbus,int_pop_size,…
please I need help in debugging this problem I am running a simulation on the location and sizing of svc on ieee 57 using pso algorithm.
It keeps displaying this error’
‘Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 1-by-3.
Error in pso_process_svc (line 31)
data_initial_pso_pop(indexloop,:) = DGsize_first_para;
Error in TOP_PSO (line 74)
[finalres,FINAL_SVC_LOCATION_SIZE,prop_best_datapso]=pso_process_svc(nbus,int_pop_size,…
please I need help in debugging this problem pso MATLAB Answers — New Questions
I want to use a backgroudpool to open a class
Hello,
I want to write a Matlab code that controls a device via an API. I want to implemement a Function that runs in the background and records data out of the device.
That is how i start the function in my maincode:
f1 = parfeval(Pool, @Measurement, 0, actualSystemValuesInstance);
The actualSystemValuesInstance variable holds the class needed to request data from the device. This is my function to handle the Task.
function [] = Measurement(actualSystemValuesInstance)
fileID = fopen(‘data.csv’, ‘a+’);
fmtstr = ‘%12.12f;%12.12f;%12.12frn’;
t = timer();
t.Period = 1;
t.ExecutionMode = ‘fixedRate’;
t.BusyMode = ‘queue’;
t.TimerFcn = @recordData;
function recordData(~, ~)
outputcurrent = actualSystemValuesInstance.GetOutputCurrent();
outputvoltage = actualSystemValuesInstance.GetOutputVoltage();
time = now;
fprintf(fileID, fmtstr, outputvoltage, outputcurrent, time);
end
end
My Problem is, that my Function isnt starting because the class is unknown. Is there a diffrent was to hand over the class to my function?
I also tried to opend and define the API with the classes in the background, there i also get an error. Furthermore I tested the same situation with parpool, there I have the same problem that the class arrives empty in my function.
Is it even possible to use parallel Functions in my application?
PS:
I wanted to use the function in the backround, that my measurements cant be blocked by other runtimes in my Maincode and i wanted to try to do it without timer controled interrrupts.Hello,
I want to write a Matlab code that controls a device via an API. I want to implemement a Function that runs in the background and records data out of the device.
That is how i start the function in my maincode:
f1 = parfeval(Pool, @Measurement, 0, actualSystemValuesInstance);
The actualSystemValuesInstance variable holds the class needed to request data from the device. This is my function to handle the Task.
function [] = Measurement(actualSystemValuesInstance)
fileID = fopen(‘data.csv’, ‘a+’);
fmtstr = ‘%12.12f;%12.12f;%12.12frn’;
t = timer();
t.Period = 1;
t.ExecutionMode = ‘fixedRate’;
t.BusyMode = ‘queue’;
t.TimerFcn = @recordData;
function recordData(~, ~)
outputcurrent = actualSystemValuesInstance.GetOutputCurrent();
outputvoltage = actualSystemValuesInstance.GetOutputVoltage();
time = now;
fprintf(fileID, fmtstr, outputvoltage, outputcurrent, time);
end
end
My Problem is, that my Function isnt starting because the class is unknown. Is there a diffrent was to hand over the class to my function?
I also tried to opend and define the API with the classes in the background, there i also get an error. Furthermore I tested the same situation with parpool, there I have the same problem that the class arrives empty in my function.
Is it even possible to use parallel Functions in my application?
PS:
I wanted to use the function in the backround, that my measurements cant be blocked by other runtimes in my Maincode and i wanted to try to do it without timer controled interrrupts. Hello,
I want to write a Matlab code that controls a device via an API. I want to implemement a Function that runs in the background and records data out of the device.
That is how i start the function in my maincode:
f1 = parfeval(Pool, @Measurement, 0, actualSystemValuesInstance);
The actualSystemValuesInstance variable holds the class needed to request data from the device. This is my function to handle the Task.
function [] = Measurement(actualSystemValuesInstance)
fileID = fopen(‘data.csv’, ‘a+’);
fmtstr = ‘%12.12f;%12.12f;%12.12frn’;
t = timer();
t.Period = 1;
t.ExecutionMode = ‘fixedRate’;
t.BusyMode = ‘queue’;
t.TimerFcn = @recordData;
function recordData(~, ~)
outputcurrent = actualSystemValuesInstance.GetOutputCurrent();
outputvoltage = actualSystemValuesInstance.GetOutputVoltage();
time = now;
fprintf(fileID, fmtstr, outputvoltage, outputcurrent, time);
end
end
My Problem is, that my Function isnt starting because the class is unknown. Is there a diffrent was to hand over the class to my function?
I also tried to opend and define the API with the classes in the background, there i also get an error. Furthermore I tested the same situation with parpool, there I have the same problem that the class arrives empty in my function.
Is it even possible to use parallel Functions in my application?
PS:
I wanted to use the function in the backround, that my measurements cant be blocked by other runtimes in my Maincode and i wanted to try to do it without timer controled interrrupts. backgroundpool, parallel computing, parfeval MATLAB Answers — New Questions
animation with the command show(robot) is very, very slow
Within a robotics class, in the control loop, I have the following code to render the robot movement:
show(robot,q_Gen,’PreservePlot’,true,’Frames’,’off’);
hold on
plot3(xd(1,1:i),xd(2,1:i),xd(3,1:i),’r’)
axis([-.4 .4 -.4 .4 -.1 1])
view(45,35)
drawnow
hold off
The robot has been defined outside of the loop by the command
robot = loadrobot(‘kinovaGen3′,’DataFormat’,’row’,’Gravity’,[0 0 -9.81]);
The animation is very, very slow in any o.s. and PC where it has been tried (Linux, Windows, MAC).
Is it a drawback that can not be avoided?Within a robotics class, in the control loop, I have the following code to render the robot movement:
show(robot,q_Gen,’PreservePlot’,true,’Frames’,’off’);
hold on
plot3(xd(1,1:i),xd(2,1:i),xd(3,1:i),’r’)
axis([-.4 .4 -.4 .4 -.1 1])
view(45,35)
drawnow
hold off
The robot has been defined outside of the loop by the command
robot = loadrobot(‘kinovaGen3′,’DataFormat’,’row’,’Gravity’,[0 0 -9.81]);
The animation is very, very slow in any o.s. and PC where it has been tried (Linux, Windows, MAC).
Is it a drawback that can not be avoided? Within a robotics class, in the control loop, I have the following code to render the robot movement:
show(robot,q_Gen,’PreservePlot’,true,’Frames’,’off’);
hold on
plot3(xd(1,1:i),xd(2,1:i),xd(3,1:i),’r’)
axis([-.4 .4 -.4 .4 -.1 1])
view(45,35)
drawnow
hold off
The robot has been defined outside of the loop by the command
robot = loadrobot(‘kinovaGen3′,’DataFormat’,’row’,’Gravity’,[0 0 -9.81]);
The animation is very, very slow in any o.s. and PC where it has been tried (Linux, Windows, MAC).
Is it a drawback that can not be avoided? drawnow, animation, show robot MATLAB Answers — New Questions
I tried this code but it gives me an error
There are 8 antennas placed in a circle and there are two sources in the far field from which rays are coming and are incident on these antennas. The mathematical formula for array factor "AF" is given in the attachment. This derivation of this formula is also attached. Now if the angles of those two sources are 30 and 70 respectively which I assign to a vector u. Then I want to put these angles one by one while spanning all the 8 antennas. I mean when I put angle 30 in the formula, then the AF should be calculated over all the 8 antennas. Likewise then put the 2nd angle 70 in the formula and calculate the AF over all the 8 antennas. So when I check the AF, it should be an 8 x 2 matrix where 8 are antennas and 2 are angles. I have tried for its code as below but it gives me an error:
clear;clc
f=1e9;% frequency
c=3e8;% speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
u=[30 70];% The two Angles
M=length(u);% Number of angles
d_circular=l/2;% spacing b/w elements
circumference = N*d_circular;
a = circumference/2*pi; % Radius
for sourceNo=1:M
for m=0:N-1
% AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))
AF(m)=sum(exp(-1i*k*a*(cos(u(sourceNo)-phi_n))));
end
end
AFThere are 8 antennas placed in a circle and there are two sources in the far field from which rays are coming and are incident on these antennas. The mathematical formula for array factor "AF" is given in the attachment. This derivation of this formula is also attached. Now if the angles of those two sources are 30 and 70 respectively which I assign to a vector u. Then I want to put these angles one by one while spanning all the 8 antennas. I mean when I put angle 30 in the formula, then the AF should be calculated over all the 8 antennas. Likewise then put the 2nd angle 70 in the formula and calculate the AF over all the 8 antennas. So when I check the AF, it should be an 8 x 2 matrix where 8 are antennas and 2 are angles. I have tried for its code as below but it gives me an error:
clear;clc
f=1e9;% frequency
c=3e8;% speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
u=[30 70];% The two Angles
M=length(u);% Number of angles
d_circular=l/2;% spacing b/w elements
circumference = N*d_circular;
a = circumference/2*pi; % Radius
for sourceNo=1:M
for m=0:N-1
% AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))
AF(m)=sum(exp(-1i*k*a*(cos(u(sourceNo)-phi_n))));
end
end
AF There are 8 antennas placed in a circle and there are two sources in the far field from which rays are coming and are incident on these antennas. The mathematical formula for array factor "AF" is given in the attachment. This derivation of this formula is also attached. Now if the angles of those two sources are 30 and 70 respectively which I assign to a vector u. Then I want to put these angles one by one while spanning all the 8 antennas. I mean when I put angle 30 in the formula, then the AF should be calculated over all the 8 antennas. Likewise then put the 2nd angle 70 in the formula and calculate the AF over all the 8 antennas. So when I check the AF, it should be an 8 x 2 matrix where 8 are antennas and 2 are angles. I have tried for its code as below but it gives me an error:
clear;clc
f=1e9;% frequency
c=3e8;% speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
u=[30 70];% The two Angles
M=length(u);% Number of angles
d_circular=l/2;% spacing b/w elements
circumference = N*d_circular;
a = circumference/2*pi; % Radius
for sourceNo=1:M
for m=0:N-1
% AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))
AF(m)=sum(exp(-1i*k*a*(cos(u(sourceNo)-phi_n))));
end
end
AF code gives an error, how to modify MATLAB Answers — New Questions
Change de default position of plot
Dear;
This a silly question
Sometimes when I debug a program I need to plot some of the variables in different figures
The figure apear just in the middle of the script editor, so to continued debugging I have to move the plot
Is there any way to chage the default position where the plot appears?
Many thanks,Dear;
This a silly question
Sometimes when I debug a program I need to plot some of the variables in different figures
The figure apear just in the middle of the script editor, so to continued debugging I have to move the plot
Is there any way to chage the default position where the plot appears?
Many thanks, Dear;
This a silly question
Sometimes when I debug a program I need to plot some of the variables in different figures
The figure apear just in the middle of the script editor, so to continued debugging I have to move the plot
Is there any way to chage the default position where the plot appears?
Many thanks, default position of plot figure MATLAB Answers — New Questions
My one-sample t-test isn’t working as I need it to.
Hello everyone. I need to calculate the p-value for each sample with different dimensions and compare them with the reference value, which is the largest sample at 100 mm. I need to perform a one-sample t-test with a significance level of 0.05. Here is my code. I don’t know why it always outputs NaN for the 80 mm value. I would like to fix this.
My Code:
% Clear the workspace, command window, and close any open figures
clc;
clear all;
close all;
% Input data
data = [67.142880, 69.218820, 67.379050, 69.943850, 67.407470]; % Data values
rozmery = [100, 80, 60, 40, 20]; % Dimensions
reference_value = data(1); % Reference value
% Significance level
alpha = 0.05;
% Initialize an array to store p-values
p_values = zeros(1, length(data) – 1);
% Perform t-tests and calculate p-values for each subsequent data point
for i = 2:length(data)
% Perform a one-sample t-test
[~, p_values(i-1)] = ttest2(data(1:i-1), data(i), ‘Alpha’, alpha);
end
% Plot the graph
figure;
plot(rozmery(2:end), p_values, ‘-o’, ‘LineWidth’, 2); % Plot dimensions against p-values
xlabel(‘Dimensions (mm)’); % X-axis label
ylabel(‘P-values’); % Y-axis label
title(‘P-values vs Dimensions’); % Title of the plot
grid on; % Turn on the grid
% Add labels to the plot
for i = 2:length(rozmery)
text(rozmery(i), p_values(i-1), sprintf(‘(%d, %f)’, rozmery(i), p_values(i-1)),…
‘VerticalAlignment’, ‘bottom’, ‘HorizontalAlignment’, ‘left’);
% Add text annotations for each point on the plot
end
% Display the corresponding dimension values and p-values
for i = 2:length(rozmery)
fprintf(‘P-value for dimension %d mm: %fn’, rozmery(i), p_values(i-1));
end
% Find the point where the p-value falls below the significance level
index_rustu = find(p_values < alpha, 1);
% Display the point where the p-value falls below the significance level
if ~isempty(index_rustu)
hold on;
plot(rozmery(index_rustu + 1), p_values(index_rustu), ‘r*’, ‘MarkerSize’, 10);
hold off;
fprintf(‘Point where the p-value falls below the significance level: %d mmn’, rozmery(index_rustu + 1));
fprintf(‘P-value at this point: %fn’, p_values(index_rustu));
else
disp(‘No point found where the p-value falls below the significance level.’);
endHello everyone. I need to calculate the p-value for each sample with different dimensions and compare them with the reference value, which is the largest sample at 100 mm. I need to perform a one-sample t-test with a significance level of 0.05. Here is my code. I don’t know why it always outputs NaN for the 80 mm value. I would like to fix this.
My Code:
% Clear the workspace, command window, and close any open figures
clc;
clear all;
close all;
% Input data
data = [67.142880, 69.218820, 67.379050, 69.943850, 67.407470]; % Data values
rozmery = [100, 80, 60, 40, 20]; % Dimensions
reference_value = data(1); % Reference value
% Significance level
alpha = 0.05;
% Initialize an array to store p-values
p_values = zeros(1, length(data) – 1);
% Perform t-tests and calculate p-values for each subsequent data point
for i = 2:length(data)
% Perform a one-sample t-test
[~, p_values(i-1)] = ttest2(data(1:i-1), data(i), ‘Alpha’, alpha);
end
% Plot the graph
figure;
plot(rozmery(2:end), p_values, ‘-o’, ‘LineWidth’, 2); % Plot dimensions against p-values
xlabel(‘Dimensions (mm)’); % X-axis label
ylabel(‘P-values’); % Y-axis label
title(‘P-values vs Dimensions’); % Title of the plot
grid on; % Turn on the grid
% Add labels to the plot
for i = 2:length(rozmery)
text(rozmery(i), p_values(i-1), sprintf(‘(%d, %f)’, rozmery(i), p_values(i-1)),…
‘VerticalAlignment’, ‘bottom’, ‘HorizontalAlignment’, ‘left’);
% Add text annotations for each point on the plot
end
% Display the corresponding dimension values and p-values
for i = 2:length(rozmery)
fprintf(‘P-value for dimension %d mm: %fn’, rozmery(i), p_values(i-1));
end
% Find the point where the p-value falls below the significance level
index_rustu = find(p_values < alpha, 1);
% Display the point where the p-value falls below the significance level
if ~isempty(index_rustu)
hold on;
plot(rozmery(index_rustu + 1), p_values(index_rustu), ‘r*’, ‘MarkerSize’, 10);
hold off;
fprintf(‘Point where the p-value falls below the significance level: %d mmn’, rozmery(index_rustu + 1));
fprintf(‘P-value at this point: %fn’, p_values(index_rustu));
else
disp(‘No point found where the p-value falls below the significance level.’);
end Hello everyone. I need to calculate the p-value for each sample with different dimensions and compare them with the reference value, which is the largest sample at 100 mm. I need to perform a one-sample t-test with a significance level of 0.05. Here is my code. I don’t know why it always outputs NaN for the 80 mm value. I would like to fix this.
My Code:
% Clear the workspace, command window, and close any open figures
clc;
clear all;
close all;
% Input data
data = [67.142880, 69.218820, 67.379050, 69.943850, 67.407470]; % Data values
rozmery = [100, 80, 60, 40, 20]; % Dimensions
reference_value = data(1); % Reference value
% Significance level
alpha = 0.05;
% Initialize an array to store p-values
p_values = zeros(1, length(data) – 1);
% Perform t-tests and calculate p-values for each subsequent data point
for i = 2:length(data)
% Perform a one-sample t-test
[~, p_values(i-1)] = ttest2(data(1:i-1), data(i), ‘Alpha’, alpha);
end
% Plot the graph
figure;
plot(rozmery(2:end), p_values, ‘-o’, ‘LineWidth’, 2); % Plot dimensions against p-values
xlabel(‘Dimensions (mm)’); % X-axis label
ylabel(‘P-values’); % Y-axis label
title(‘P-values vs Dimensions’); % Title of the plot
grid on; % Turn on the grid
% Add labels to the plot
for i = 2:length(rozmery)
text(rozmery(i), p_values(i-1), sprintf(‘(%d, %f)’, rozmery(i), p_values(i-1)),…
‘VerticalAlignment’, ‘bottom’, ‘HorizontalAlignment’, ‘left’);
% Add text annotations for each point on the plot
end
% Display the corresponding dimension values and p-values
for i = 2:length(rozmery)
fprintf(‘P-value for dimension %d mm: %fn’, rozmery(i), p_values(i-1));
end
% Find the point where the p-value falls below the significance level
index_rustu = find(p_values < alpha, 1);
% Display the point where the p-value falls below the significance level
if ~isempty(index_rustu)
hold on;
plot(rozmery(index_rustu + 1), p_values(index_rustu), ‘r*’, ‘MarkerSize’, 10);
hold off;
fprintf(‘Point where the p-value falls below the significance level: %d mmn’, rozmery(index_rustu + 1));
fprintf(‘P-value at this point: %fn’, p_values(index_rustu));
else
disp(‘No point found where the p-value falls below the significance level.’);
end statistics, t-test MATLAB Answers — New Questions
triple nested integral with error “Arrays have incompatible sizes for this operation.”
Hi! I have a code in which there are three integrals, nested inside one another. These are the functions:
function integral_z = integral_z(z0, a, y, P, A, omega0, to)
fe = f_e(z0, P);
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
integral_z = fe.*F0(insideF0);
end
function Integrand = Integrand(a, y, P, A, omega0, to)
z0_min = ((P.p-2)./(P.p-1))./(1-P.geratio.^(2-P.p));
z0_max = P.geratio.*z0_min;
% calling first integral
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
end
function IntegrandY = IntegrandY(y, P, A, omega0, to)
% calling second integral
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
end
and I call IntegrandY as follows:
% calling third integral
integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
But I get the following error:
Arrays have incompatible sizes for this operation.
Error in F_BM_Analytic_Cooling/integral_z (line 49)
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
Error in F_BM_Analytic_Cooling>@(z0)integral_z(z0,a,y,P,A,omega0,to) (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in integralCalc/iterateScalarValued (line 323)
fx = FUN(t).*w;
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 F_BM_Analytic_Cooling/Integrand (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in F_BM_Analytic_Cooling>@(a)Integrand(a,y,P,A,omega0,to) (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
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 F_BM_Analytic_Cooling/IntegrandY (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
Error in F_BM_Analytic_Cooling>@(y)IntegrandY(y,P,A,omega0,to) (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
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 F_BM_Analytic_Cooling (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
In order to find out more, I paused the code each time one of the functions is called. That showed me that the first time integral_z is called everything runs smoothly, and y, a and z0 all have the same size (1X150). Then, for a reason I don’t understand, integral_z is called a second time with the same y, a only with a different z0, of a different size, (1X90). I don’t understand why would integral_z be called again, and I’m really clueless as of what to do.
Any help would be greatly appriciated!Hi! I have a code in which there are three integrals, nested inside one another. These are the functions:
function integral_z = integral_z(z0, a, y, P, A, omega0, to)
fe = f_e(z0, P);
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
integral_z = fe.*F0(insideF0);
end
function Integrand = Integrand(a, y, P, A, omega0, to)
z0_min = ((P.p-2)./(P.p-1))./(1-P.geratio.^(2-P.p));
z0_max = P.geratio.*z0_min;
% calling first integral
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
end
function IntegrandY = IntegrandY(y, P, A, omega0, to)
% calling second integral
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
end
and I call IntegrandY as follows:
% calling third integral
integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
But I get the following error:
Arrays have incompatible sizes for this operation.
Error in F_BM_Analytic_Cooling/integral_z (line 49)
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
Error in F_BM_Analytic_Cooling>@(z0)integral_z(z0,a,y,P,A,omega0,to) (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in integralCalc/iterateScalarValued (line 323)
fx = FUN(t).*w;
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 F_BM_Analytic_Cooling/Integrand (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in F_BM_Analytic_Cooling>@(a)Integrand(a,y,P,A,omega0,to) (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
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 F_BM_Analytic_Cooling/IntegrandY (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
Error in F_BM_Analytic_Cooling>@(y)IntegrandY(y,P,A,omega0,to) (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
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 F_BM_Analytic_Cooling (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
In order to find out more, I paused the code each time one of the functions is called. That showed me that the first time integral_z is called everything runs smoothly, and y, a and z0 all have the same size (1X150). Then, for a reason I don’t understand, integral_z is called a second time with the same y, a only with a different z0, of a different size, (1X90). I don’t understand why would integral_z be called again, and I’m really clueless as of what to do.
Any help would be greatly appriciated! Hi! I have a code in which there are three integrals, nested inside one another. These are the functions:
function integral_z = integral_z(z0, a, y, P, A, omega0, to)
fe = f_e(z0, P);
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
integral_z = fe.*F0(insideF0);
end
function Integrand = Integrand(a, y, P, A, omega0, to)
z0_min = ((P.p-2)./(P.p-1))./(1-P.geratio.^(2-P.p));
z0_max = P.geratio.*z0_min;
% calling first integral
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
end
function IntegrandY = IntegrandY(y, P, A, omega0, to)
% calling second integral
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
end
and I call IntegrandY as follows:
% calling third integral
integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
But I get the following error:
Arrays have incompatible sizes for this operation.
Error in F_BM_Analytic_Cooling/integral_z (line 49)
insideF0 = 2.*a.*(1+7.*(a.^2)).*(2*pi*P.nu/omega0).*(to.^(3/2)).*(z0.^(-1) + A.*(8.*to).^(-1/2).*a.^(-1).*y.^(-2).*(1-y.^(16/9))).^2;
Error in F_BM_Analytic_Cooling>@(z0)integral_z(z0,a,y,P,A,omega0,to) (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in integralCalc/iterateScalarValued (line 323)
fx = FUN(t).*w;
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 F_BM_Analytic_Cooling/Integrand (line 56)
Integrand = ((a.^3).*((1+7.*(a.^2)).^(-2))).*integral(@(z0)integral_z(z0, a, y, P, A, omega0, to), z0_min, z0_max);
Error in F_BM_Analytic_Cooling>@(a)Integrand(a,y,P,A,omega0,to) (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
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 F_BM_Analytic_Cooling/IntegrandY (line 60)
IntegrandY = y.^3.*integral(@(a)Integrand(a, y, P, A, omega0, to), 0, 1);
Error in F_BM_Analytic_Cooling>@(y)IntegrandY(y,P,A,omega0,to) (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
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 F_BM_Analytic_Cooling (line 27)
int2 = integral(@(y)IntegrandY(y, P, A, omega0, to),0,1);
In order to find out more, I paused the code each time one of the functions is called. That showed me that the first time integral_z is called everything runs smoothly, and y, a and z0 all have the same size (1X150). Then, for a reason I don’t understand, integral_z is called a second time with the same y, a only with a different z0, of a different size, (1X90). I don’t understand why would integral_z be called again, and I’m really clueless as of what to do.
Any help would be greatly appriciated! integration, integral, arrays, function MATLAB Answers — New Questions
Add listener programmatically for each object method
Hello there!
I have the following situation: Let’s say I have a class:
classdef Calculator < handle & matlab.mixin.Heterogeneous
methods
function obj = Calculator()
… constructor code
end
function val = veryExpensiveMethod(argsAsObj)
… some very time consuming code
end
function val = calledByListener(listenerArgs, methodName, argsAsObj)
… some code to check stuff
fcn_handle = str2func(methodName);
val = fcn_handle(argsAsObj);
end
end
end
Is it possible to add a listener to the specific method veryExpensiveMethod, where the listener will have access to the input argument argsAsObj of the method and is called automatically, without using notify()? The callback should be calledByListener. Essentially, the idea would be, that I can implement the method veryExpensiveMethod without thinking about firing events, but each call to the method will automatically fire such an event, and consequently call calledByListener.
I saw that you can add listeners to object properties (preGet, postGet, preSet, postSet) – which is essentially what I need, but I need it for a method call – e.g., preCalled.
In the example it is important that the class inherits from Heterogeneous. This is crucial, thus I cannot use RedefineDot operations in order to trigger events, which is not compatible with Heterogeneous. Anyways, dumping the Heterogeneous from the class definition would not solve the problem entirely, since RedefineDot is only triggered when object methods are called publicly (from the outside), but not if one method calls another method inside the object. In addition, RedefineDot does not have access to the method call’s input arguments.
So, is it possible to have automatic/programmatic listener creation based on a method name, that creates a preCalled listener for a method? I can use the call stack, if that helps.
Best regards and thanks a lot in advance!
TEHello there!
I have the following situation: Let’s say I have a class:
classdef Calculator < handle & matlab.mixin.Heterogeneous
methods
function obj = Calculator()
… constructor code
end
function val = veryExpensiveMethod(argsAsObj)
… some very time consuming code
end
function val = calledByListener(listenerArgs, methodName, argsAsObj)
… some code to check stuff
fcn_handle = str2func(methodName);
val = fcn_handle(argsAsObj);
end
end
end
Is it possible to add a listener to the specific method veryExpensiveMethod, where the listener will have access to the input argument argsAsObj of the method and is called automatically, without using notify()? The callback should be calledByListener. Essentially, the idea would be, that I can implement the method veryExpensiveMethod without thinking about firing events, but each call to the method will automatically fire such an event, and consequently call calledByListener.
I saw that you can add listeners to object properties (preGet, postGet, preSet, postSet) – which is essentially what I need, but I need it for a method call – e.g., preCalled.
In the example it is important that the class inherits from Heterogeneous. This is crucial, thus I cannot use RedefineDot operations in order to trigger events, which is not compatible with Heterogeneous. Anyways, dumping the Heterogeneous from the class definition would not solve the problem entirely, since RedefineDot is only triggered when object methods are called publicly (from the outside), but not if one method calls another method inside the object. In addition, RedefineDot does not have access to the method call’s input arguments.
So, is it possible to have automatic/programmatic listener creation based on a method name, that creates a preCalled listener for a method? I can use the call stack, if that helps.
Best regards and thanks a lot in advance!
TE Hello there!
I have the following situation: Let’s say I have a class:
classdef Calculator < handle & matlab.mixin.Heterogeneous
methods
function obj = Calculator()
… constructor code
end
function val = veryExpensiveMethod(argsAsObj)
… some very time consuming code
end
function val = calledByListener(listenerArgs, methodName, argsAsObj)
… some code to check stuff
fcn_handle = str2func(methodName);
val = fcn_handle(argsAsObj);
end
end
end
Is it possible to add a listener to the specific method veryExpensiveMethod, where the listener will have access to the input argument argsAsObj of the method and is called automatically, without using notify()? The callback should be calledByListener. Essentially, the idea would be, that I can implement the method veryExpensiveMethod without thinking about firing events, but each call to the method will automatically fire such an event, and consequently call calledByListener.
I saw that you can add listeners to object properties (preGet, postGet, preSet, postSet) – which is essentially what I need, but I need it for a method call – e.g., preCalled.
In the example it is important that the class inherits from Heterogeneous. This is crucial, thus I cannot use RedefineDot operations in order to trigger events, which is not compatible with Heterogeneous. Anyways, dumping the Heterogeneous from the class definition would not solve the problem entirely, since RedefineDot is only triggered when object methods are called publicly (from the outside), but not if one method calls another method inside the object. In addition, RedefineDot does not have access to the method call’s input arguments.
So, is it possible to have automatic/programmatic listener creation based on a method name, that creates a preCalled listener for a method? I can use the call stack, if that helps.
Best regards and thanks a lot in advance!
TE addlistener, listener, method call, programmatically create listener MATLAB Answers — New Questions
Optimizing lsqnonlin for Nonlinear Inverse Problems: Handling Large Unknown Parameter Sizes and Measurement Datasets
Can anyone provide insights or guidance on effectively utilizing the lsqnonlin function with the Levenberg-Marquardt algorithm and Tikhonov regularization for solving a nonlinear inverse problem with a large unknown parameter size of 109 and 380 measurements? Any tips on parameter initialization, optimization options, and dealing with computational challenges would be greatly appreciated!Can anyone provide insights or guidance on effectively utilizing the lsqnonlin function with the Levenberg-Marquardt algorithm and Tikhonov regularization for solving a nonlinear inverse problem with a large unknown parameter size of 109 and 380 measurements? Any tips on parameter initialization, optimization options, and dealing with computational challenges would be greatly appreciated! Can anyone provide insights or guidance on effectively utilizing the lsqnonlin function with the Levenberg-Marquardt algorithm and Tikhonov regularization for solving a nonlinear inverse problem with a large unknown parameter size of 109 and 380 measurements? Any tips on parameter initialization, optimization options, and dealing with computational challenges would be greatly appreciated! transferred MATLAB Answers — New Questions
is there any way to keep the uninitialized variable in parfor and recall it outside
Hi
This is how it look like my code:
b = [];
parfor i = 1:n
for j=1:m
if b && some_condition(i)
t=do_something(i);
b = [b;t];
end
end…
end
I want to save b matrix for every itration , please help
BestHi
This is how it look like my code:
b = [];
parfor i = 1:n
for j=1:m
if b && some_condition(i)
t=do_something(i);
b = [b;t];
end
end…
end
I want to save b matrix for every itration , please help
Best Hi
This is how it look like my code:
b = [];
parfor i = 1:n
for j=1:m
if b && some_condition(i)
t=do_something(i);
b = [b;t];
end
end…
end
I want to save b matrix for every itration , please help
Best temporary variable, parfor, matlab MATLAB Answers — New Questions
Difficulties with symbolically integrating Paris law equation
Apologies if this is rudimentary, I have little experience using matlab for symbolic intergration.
I am atempting to write the following intergral into matlab.
however my script shows "incorect number of inputs", I am using the intergration command the way it is presented on the help page but I seem to be gettinging something wrongApologies if this is rudimentary, I have little experience using matlab for symbolic intergration.
I am atempting to write the following intergral into matlab.
however my script shows "incorect number of inputs", I am using the intergration command the way it is presented on the help page but I seem to be gettinging something wrong Apologies if this is rudimentary, I have little experience using matlab for symbolic intergration.
I am atempting to write the following intergral into matlab.
however my script shows "incorect number of inputs", I am using the intergration command the way it is presented on the help page but I seem to be gettinging something wrong integration, symbolic MATLAB Answers — New Questions
Converting TIFF cell array sequence to video
I am trying to take a multipage tiff file and convert it to video, I’m not proficient in Matlab at all.
I’m using code that I found on a tutorial for converting multipage tiff images into seperate viewable images. The code is as follows:
fname = ‘vid.tiff’;
info = imfinfo(fname);
num_images = numel(info);
for k = 1:num_images
A(:,:,k) = imread(fname, k, ‘Info’, info);
end
mplay(A);
I originally had the imread saving to a cell array, but that didn’t work with mplay, so I changed it to a matrix. It seems to work as it runs a video of the right number of frames after I run the script, but the video that plays is only black images. I know the images have information in them because I can view each of them seperately. I’m honestly not even sure what this code does, I just know that it seems to work up until the video output.I am trying to take a multipage tiff file and convert it to video, I’m not proficient in Matlab at all.
I’m using code that I found on a tutorial for converting multipage tiff images into seperate viewable images. The code is as follows:
fname = ‘vid.tiff’;
info = imfinfo(fname);
num_images = numel(info);
for k = 1:num_images
A(:,:,k) = imread(fname, k, ‘Info’, info);
end
mplay(A);
I originally had the imread saving to a cell array, but that didn’t work with mplay, so I changed it to a matrix. It seems to work as it runs a video of the right number of frames after I run the script, but the video that plays is only black images. I know the images have information in them because I can view each of them seperately. I’m honestly not even sure what this code does, I just know that it seems to work up until the video output. I am trying to take a multipage tiff file and convert it to video, I’m not proficient in Matlab at all.
I’m using code that I found on a tutorial for converting multipage tiff images into seperate viewable images. The code is as follows:
fname = ‘vid.tiff’;
info = imfinfo(fname);
num_images = numel(info);
for k = 1:num_images
A(:,:,k) = imread(fname, k, ‘Info’, info);
end
mplay(A);
I originally had the imread saving to a cell array, but that didn’t work with mplay, so I changed it to a matrix. It seems to work as it runs a video of the right number of frames after I run the script, but the video that plays is only black images. I know the images have information in them because I can view each of them seperately. I’m honestly not even sure what this code does, I just know that it seems to work up until the video output. tiff MATLAB Answers — New Questions
‘Error in port widths or dimensions’ I can’t solve it
Error in port widths or dimensions.Error in port widths or dimensions. Error in port widths or dimensions. error in port widths or dimensions MATLAB Answers — New Questions
Choosing a suitable fit for the graph
Hi,
I’m a begginer in matlab, so maybe it’s simple, but I couldn’t find an answer online..
I work on scanning from fabry-perot, and I need to do fit on the plot. I’m not sure what type of fit I should use, here’s the graph I have from the scan:
I found how to make a Gaussian fit for example, but this fit does not fit my graph.. Where can I see all the types of fits that exist? Or maybe I should make a fit with my own function? And if so, how do you do it?
I would appreciate help in terms of choosing the appropriate fit if you have an idea, and also help in terms of the code and how to do it.
Thank you!Hi,
I’m a begginer in matlab, so maybe it’s simple, but I couldn’t find an answer online..
I work on scanning from fabry-perot, and I need to do fit on the plot. I’m not sure what type of fit I should use, here’s the graph I have from the scan:
I found how to make a Gaussian fit for example, but this fit does not fit my graph.. Where can I see all the types of fits that exist? Or maybe I should make a fit with my own function? And if so, how do you do it?
I would appreciate help in terms of choosing the appropriate fit if you have an idea, and also help in terms of the code and how to do it.
Thank you! Hi,
I’m a begginer in matlab, so maybe it’s simple, but I couldn’t find an answer online..
I work on scanning from fabry-perot, and I need to do fit on the plot. I’m not sure what type of fit I should use, here’s the graph I have from the scan:
I found how to make a Gaussian fit for example, but this fit does not fit my graph.. Where can I see all the types of fits that exist? Or maybe I should make a fit with my own function? And if so, how do you do it?
I would appreciate help in terms of choosing the appropriate fit if you have an idea, and also help in terms of the code and how to do it.
Thank you! curve fitting, matlab code MATLAB Answers — New Questions
Generate staircase waveform from given sine waveform in Simulink
Hi,
I want to generate a staircase waveform from the following waveform
Vin = 0.5(1+sin(wt));// wt = 2*pi*50;
with following procedure:
1) Mark the blocks of fixed duration (eg: 25msec) for the entire waveform.
2) Average the waveform within each block and output the waveform with each horizontal line in a block indicating the average value of the waveform.Hi,
I want to generate a staircase waveform from the following waveform
Vin = 0.5(1+sin(wt));// wt = 2*pi*50;
with following procedure:
1) Mark the blocks of fixed duration (eg: 25msec) for the entire waveform.
2) Average the waveform within each block and output the waveform with each horizontal line in a block indicating the average value of the waveform. Hi,
I want to generate a staircase waveform from the following waveform
Vin = 0.5(1+sin(wt));// wt = 2*pi*50;
with following procedure:
1) Mark the blocks of fixed duration (eg: 25msec) for the entire waveform.
2) Average the waveform within each block and output the waveform with each horizontal line in a block indicating the average value of the waveform. simulink, waveformgeneration MATLAB Answers — New Questions