Category: Matlab
Category Archives: Matlab
Error (misclassification probability or MSE)
Hi all. I am trying to use the Error (misclassification probability or MSE) function. In the help documentation it shows an example of useage as err = error(B,TBLnew,Ynew). I tried this with err=error(Mdl,Inps,Outs) with Mdl being the LSBOOST ensemble, Inps being the matrix of vars and Outs being the target. If I try this I get ‘Error using error Too many output arguments.’ . I presume I’m missing something here but can’t seem to find a an example.Hi all. I am trying to use the Error (misclassification probability or MSE) function. In the help documentation it shows an example of useage as err = error(B,TBLnew,Ynew). I tried this with err=error(Mdl,Inps,Outs) with Mdl being the LSBOOST ensemble, Inps being the matrix of vars and Outs being the target. If I try this I get ‘Error using error Too many output arguments.’ . I presume I’m missing something here but can’t seem to find a an example. Hi all. I am trying to use the Error (misclassification probability or MSE) function. In the help documentation it shows an example of useage as err = error(B,TBLnew,Ynew). I tried this with err=error(Mdl,Inps,Outs) with Mdl being the LSBOOST ensemble, Inps being the matrix of vars and Outs being the target. If I try this I get ‘Error using error Too many output arguments.’ . I presume I’m missing something here but can’t seem to find a an example. mse, lsboost, ensemble, error MATLAB Answers — New Questions
An error occurred (‘RTW:buildProcess:fatalBuildError’) when calling ‘sim’: error while running SIL Simulation in Test manager
I am running SIL in test manager enviornment and my test cases are failing randomly with the error saying,
An error occurred (‘RTW:buildProcess:fatalBuildError’) when calling ‘sim’:
Error(s) encountered while building "XXX_rtwlib"
While the code for model is getting generated without any issues.
Could you please assist me in resolving the issueI am running SIL in test manager enviornment and my test cases are failing randomly with the error saying,
An error occurred (‘RTW:buildProcess:fatalBuildError’) when calling ‘sim’:
Error(s) encountered while building "XXX_rtwlib"
While the code for model is getting generated without any issues.
Could you please assist me in resolving the issue I am running SIL in test manager enviornment and my test cases are failing randomly with the error saying,
An error occurred (‘RTW:buildProcess:fatalBuildError’) when calling ‘sim’:
Error(s) encountered while building "XXX_rtwlib"
While the code for model is getting generated without any issues.
Could you please assist me in resolving the issue (‘rtw:buildprocess:fatalbuilderror’) when calling MATLAB Answers — New Questions
Error: Function definition not supported in this context. Create functions in code file.
Hello,
I was trying to create a simple function on matlab, I already have a file named "AddOne.m", so it should work, however at the first line of code, matlab throws the following error
"Error: Function definition not supported in this context. Create functions in code file.". Any ideas how to sort this out?
Thanks in advance!Hello,
I was trying to create a simple function on matlab, I already have a file named "AddOne.m", so it should work, however at the first line of code, matlab throws the following error
"Error: Function definition not supported in this context. Create functions in code file.". Any ideas how to sort this out?
Thanks in advance! Hello,
I was trying to create a simple function on matlab, I already have a file named "AddOne.m", so it should work, however at the first line of code, matlab throws the following error
"Error: Function definition not supported in this context. Create functions in code file.". Any ideas how to sort this out?
Thanks in advance! function, matlab function, error MATLAB Answers — New Questions
how do i plot the following signal in matlab? x(n)=4u(n)-u(n-1)-u(n-2)-2u(n-3)
plz include steps so that i will be able to do it properly.plz include steps so that i will be able to do it properly. plz include steps so that i will be able to do it properly. continuous time signal MATLAB Answers — New Questions
How to make sure that the horizontal axes of two figures align?
I have two figures, which I want to put side by side in my thesis.
These two figures have different x and y labels and ticks, therefore, generally their horizontal axes are not on the same height.
That is ugly.
How to make sure the horizontal axes align?I have two figures, which I want to put side by side in my thesis.
These two figures have different x and y labels and ticks, therefore, generally their horizontal axes are not on the same height.
That is ugly.
How to make sure the horizontal axes align? I have two figures, which I want to put side by side in my thesis.
These two figures have different x and y labels and ticks, therefore, generally their horizontal axes are not on the same height.
That is ugly.
How to make sure the horizontal axes align? plot MATLAB Answers — New Questions
Simulink Support Package for Parrot Minidrones flight log analyze
I am conducting flight tests using the Simulink Support Package for Parrot Minidrones.
After completing the flight tests, I am analyzing the flight log and encountered the following motor values: [motor values: 301.137787 -294.847717 272.892029 -285.380737].
I am unsure whether these motor values are in the units of PWM, rad/s, or rpm.
Could you please let me know where I can find this information?I am conducting flight tests using the Simulink Support Package for Parrot Minidrones.
After completing the flight tests, I am analyzing the flight log and encountered the following motor values: [motor values: 301.137787 -294.847717 272.892029 -285.380737].
I am unsure whether these motor values are in the units of PWM, rad/s, or rpm.
Could you please let me know where I can find this information? I am conducting flight tests using the Simulink Support Package for Parrot Minidrones.
After completing the flight tests, I am analyzing the flight log and encountered the following motor values: [motor values: 301.137787 -294.847717 272.892029 -285.380737].
I am unsure whether these motor values are in the units of PWM, rad/s, or rpm.
Could you please let me know where I can find this information? simulink support package for parrot minidrones, mambo drone, flight log analyze MATLAB Answers — New Questions
Designfilt and bandstopfir adds +320dB for some reason
Good evening!
I am trying to create a set of FIR filters (using designfilt) to apply to some audio signals, and I’m having an issue.
When I try to use a ‘bandstopfir’, for some reason the whole signal is amplified around +320dB (while ‘bandpassfir’, ‘lowpassfir’ and ‘highpassfir’ are working correctly)
Here’s a quick example of the code I’m using, and I added the resulting images of each of these cases showing the issue:
clear
filterObject1 = designfilt(‘bandstopfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
filterObject2 = designfilt(‘bandpassfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
Here are images using fvtool to show both filter responses:
Bandstop (incorrect behaviour):
Bandpass (expected behaviour):
Is this a bug, is the installation I’m using somehow broken, or am I doing something wrong?Good evening!
I am trying to create a set of FIR filters (using designfilt) to apply to some audio signals, and I’m having an issue.
When I try to use a ‘bandstopfir’, for some reason the whole signal is amplified around +320dB (while ‘bandpassfir’, ‘lowpassfir’ and ‘highpassfir’ are working correctly)
Here’s a quick example of the code I’m using, and I added the resulting images of each of these cases showing the issue:
clear
filterObject1 = designfilt(‘bandstopfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
filterObject2 = designfilt(‘bandpassfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
Here are images using fvtool to show both filter responses:
Bandstop (incorrect behaviour):
Bandpass (expected behaviour):
Is this a bug, is the installation I’m using somehow broken, or am I doing something wrong? Good evening!
I am trying to create a set of FIR filters (using designfilt) to apply to some audio signals, and I’m having an issue.
When I try to use a ‘bandstopfir’, for some reason the whole signal is amplified around +320dB (while ‘bandpassfir’, ‘lowpassfir’ and ‘highpassfir’ are working correctly)
Here’s a quick example of the code I’m using, and I added the resulting images of each of these cases showing the issue:
clear
filterObject1 = designfilt(‘bandstopfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
filterObject2 = designfilt(‘bandpassfir’,’FilterOrder’,301,…
‘CutoffFrequency1′,2000,’CutoffFrequency2′,4000,’SampleRate’,48000);
Here are images using fvtool to show both filter responses:
Bandstop (incorrect behaviour):
Bandpass (expected behaviour):
Is this a bug, is the installation I’m using somehow broken, or am I doing something wrong? designfilt, filter, bandstopfir, matlab MATLAB Answers — New Questions
find a value & store in new variable (again)
Dear Matlab friends,
We recently posted a question about finding values and storing them in new variables:
http://www.mathworks.com/matlabcentral/answers/31471-find-a-value-store-in-new-variable
Our question remains in the sense that we would like to know how to procede when we have a matrix rathen than a cell array.
Indeed, we have a 384 x 14 matrix A, and we would like to find all occurrences of number [2] in column 1, and save corresponded value in column 2 in a new variable "new_variable":
A =
3 5 6 …
2 3 5
2 3 4
1 4 5
5 7 9
…
so the result would be:
new_variable =
2
2
The suggestion for cell arrays was
new_variable = A{2}(A{1} == 2);
We thank you very much for any suggestion!
Best,
UdiubuDear Matlab friends,
We recently posted a question about finding values and storing them in new variables:
http://www.mathworks.com/matlabcentral/answers/31471-find-a-value-store-in-new-variable
Our question remains in the sense that we would like to know how to procede when we have a matrix rathen than a cell array.
Indeed, we have a 384 x 14 matrix A, and we would like to find all occurrences of number [2] in column 1, and save corresponded value in column 2 in a new variable "new_variable":
A =
3 5 6 …
2 3 5
2 3 4
1 4 5
5 7 9
…
so the result would be:
new_variable =
2
2
The suggestion for cell arrays was
new_variable = A{2}(A{1} == 2);
We thank you very much for any suggestion!
Best,
Udiubu Dear Matlab friends,
We recently posted a question about finding values and storing them in new variables:
http://www.mathworks.com/matlabcentral/answers/31471-find-a-value-store-in-new-variable
Our question remains in the sense that we would like to know how to procede when we have a matrix rathen than a cell array.
Indeed, we have a 384 x 14 matrix A, and we would like to find all occurrences of number [2] in column 1, and save corresponded value in column 2 in a new variable "new_variable":
A =
3 5 6 …
2 3 5
2 3 4
1 4 5
5 7 9
…
so the result would be:
new_variable =
2
2
The suggestion for cell arrays was
new_variable = A{2}(A{1} == 2);
We thank you very much for any suggestion!
Best,
Udiubu save, variable, find MATLAB Answers — New Questions
How to calculate velocity potential using netcdf winds?
I have to calculate the velocity potential of the u and v components of the wind variables inside a netcdf file.
Thing is Im very lost at how to calculate it on maltab. Any suggestion would be very helpful.I have to calculate the velocity potential of the u and v components of the wind variables inside a netcdf file.
Thing is Im very lost at how to calculate it on maltab. Any suggestion would be very helpful. I have to calculate the velocity potential of the u and v components of the wind variables inside a netcdf file.
Thing is Im very lost at how to calculate it on maltab. Any suggestion would be very helpful. meteorology, mathematics, physics, matlab, netcdf MATLAB Answers — New Questions
How would one go about using Matlab to stop data acquisition at a certain threshold?
I’m working on a project involving taking in data, and I need to design a code which will stop the data collection once a certain threshold has been reached. I have a separate Python based program which I am using to take in the data, but I want to use Matlab in order to examine the data, while it is being acquired, and stop dats acquisition at a certain threshold. So to say, once data X reaches threshold Y, then warning Z will be displayed and data acquisition will be discontinued.I’m working on a project involving taking in data, and I need to design a code which will stop the data collection once a certain threshold has been reached. I have a separate Python based program which I am using to take in the data, but I want to use Matlab in order to examine the data, while it is being acquired, and stop dats acquisition at a certain threshold. So to say, once data X reaches threshold Y, then warning Z will be displayed and data acquisition will be discontinued. I’m working on a project involving taking in data, and I need to design a code which will stop the data collection once a certain threshold has been reached. I have a separate Python based program which I am using to take in the data, but I want to use Matlab in order to examine the data, while it is being acquired, and stop dats acquisition at a certain threshold. So to say, once data X reaches threshold Y, then warning Z will be displayed and data acquisition will be discontinued. data acquisition MATLAB Answers — New Questions
I have the wrong code. How should I modify it to accomplish the goal?
Post Content Post Content homework MATLAB Answers — New Questions
How do i extract ‘x’ and ‘y’data from ‘z’data? f(x,y)=z
I have ‘x’ data, ‘y’ data, ‘z1’ data ‘z2’ data.
It has two variable values(‘z1’, ‘z2’) at the same coordinates(x,y).
x : an integer from 1 to 13
y : an integer from 1 to 19
Z1: 13*19
I used cftool to plot the mesh. ( Interpolation)
How do I extract ‘x’ and ‘y’ data from ‘z1’ ‘z2’?
I want to estimate the coordinates by comparing the x,y data( extracted through z1)
with the x,y data (extracted through z2).
A simple example is similar to finding approximate coordinates by estimating longitude based on time and latitude based on temperature, (confined to a northern (lower hemisphere) region.)
After moving the cftool result to the workspace (name: fittedmodel_z1), in the command window, use a value with a decimal point, not an integer, within the range (~13, ~19) for x and y, such as ‘fittedmodel_z1(10.1,3.7)’ When I give the command, I can get z1 data.
How do I do it in reverse?
I want to use f(x,y)=a , but I don’t know the function f(x,y) .
Cannot use formula(fittedmodel_Z1).
>> formula(fittedmodel_Z1)
ans =
‘piecewise linear surface’
I just want to know the coordinates through the overlapping part like the red hatched part in the picture below.
How about using artificial intelligence like a classification model? Or fuzzy?
Thank you.I have ‘x’ data, ‘y’ data, ‘z1’ data ‘z2’ data.
It has two variable values(‘z1’, ‘z2’) at the same coordinates(x,y).
x : an integer from 1 to 13
y : an integer from 1 to 19
Z1: 13*19
I used cftool to plot the mesh. ( Interpolation)
How do I extract ‘x’ and ‘y’ data from ‘z1’ ‘z2’?
I want to estimate the coordinates by comparing the x,y data( extracted through z1)
with the x,y data (extracted through z2).
A simple example is similar to finding approximate coordinates by estimating longitude based on time and latitude based on temperature, (confined to a northern (lower hemisphere) region.)
After moving the cftool result to the workspace (name: fittedmodel_z1), in the command window, use a value with a decimal point, not an integer, within the range (~13, ~19) for x and y, such as ‘fittedmodel_z1(10.1,3.7)’ When I give the command, I can get z1 data.
How do I do it in reverse?
I want to use f(x,y)=a , but I don’t know the function f(x,y) .
Cannot use formula(fittedmodel_Z1).
>> formula(fittedmodel_Z1)
ans =
‘piecewise linear surface’
I just want to know the coordinates through the overlapping part like the red hatched part in the picture below.
How about using artificial intelligence like a classification model? Or fuzzy?
Thank you. I have ‘x’ data, ‘y’ data, ‘z1’ data ‘z2’ data.
It has two variable values(‘z1’, ‘z2’) at the same coordinates(x,y).
x : an integer from 1 to 13
y : an integer from 1 to 19
Z1: 13*19
I used cftool to plot the mesh. ( Interpolation)
How do I extract ‘x’ and ‘y’ data from ‘z1’ ‘z2’?
I want to estimate the coordinates by comparing the x,y data( extracted through z1)
with the x,y data (extracted through z2).
A simple example is similar to finding approximate coordinates by estimating longitude based on time and latitude based on temperature, (confined to a northern (lower hemisphere) region.)
After moving the cftool result to the workspace (name: fittedmodel_z1), in the command window, use a value with a decimal point, not an integer, within the range (~13, ~19) for x and y, such as ‘fittedmodel_z1(10.1,3.7)’ When I give the command, I can get z1 data.
How do I do it in reverse?
I want to use f(x,y)=a , but I don’t know the function f(x,y) .
Cannot use formula(fittedmodel_Z1).
>> formula(fittedmodel_Z1)
ans =
‘piecewise linear surface’
I just want to know the coordinates through the overlapping part like the red hatched part in the picture below.
How about using artificial intelligence like a classification model? Or fuzzy?
Thank you. mesh, curve fitting, cftool, f(xy)=z, fuzzy, classification, learning, data, plot, formula MATLAB Answers — New Questions
read columns on command
what he mean it here and how I write the command :what he mean it here and how I write the command : what he mean it here and how I write the command : matlab MATLAB Answers — New Questions
Different results for same equation in curve fitting
Why is custom fitting not the same as the exponential default one as shown in the picture? The data fits nicely when I use the ‘exp2’ instead.
I’m relatively new to MATLAB and this is quite baffling to me as i am unable to use a custom equation as it simply does not fit.Why is custom fitting not the same as the exponential default one as shown in the picture? The data fits nicely when I use the ‘exp2’ instead.
I’m relatively new to MATLAB and this is quite baffling to me as i am unable to use a custom equation as it simply does not fit. Why is custom fitting not the same as the exponential default one as shown in the picture? The data fits nicely when I use the ‘exp2’ instead.
I’m relatively new to MATLAB and this is quite baffling to me as i am unable to use a custom equation as it simply does not fit. curve fitting MATLAB Answers — New Questions
GUI Matlab real time data storage using DataAcquisition Interface
Hope you all well, i have GUI app which is getting data from national instrument and give back live plot after trun switch on and when switch is off the recorded data wil stop and real time data will stop, however i am trying to intesert another button to clear the previous or delete them from store array however it won’t happened i tried clear func and clf to remove plot and delete the array nothing working i will place the code blow and screen shot of the app design if you could help me to solve this i would be supre greatfull to you what i want is that the previouse data from block 1 and 2 get deleted after clear data button is clicked
classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Tab matlab.ui.container.Tab
CleardataButton matlab.ui.control.Button
DistancemmEditField matlab.ui.control.NumericEditField
DistancemmEditFieldLabel matlab.ui.control.Label
VoltageLEditField matlab.ui.control.NumericEditField
VoltageLEditFieldLabel matlab.ui.control.Label
LoadNEditField matlab.ui.control.NumericEditField
LoadNEditFieldLabel matlab.ui.control.Label
VoltageEditField matlab.ui.control.NumericEditField
VoltageEditFieldLabel matlab.ui.control.Label
SAVEDATAButton matlab.ui.control.Button
Lamp matlab.ui.control.Lamp
LampLabel matlab.ui.control.Label
Switch matlab.ui.control.Switch
SwitchLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
dq = daq("ni"); % Create a DataAcquisition object.
R = 5000;% Description
% % Arrays to store data for plotting
% timeData = [];
% loadData = [];
% distanceData = [];
end
properties (Access = public)
voltage
distance
load
f1
f2
timeData = [];
loadData = [];
distanceData = [];
end
methods (Access = public)
%
function getdat(app,src,~)
[d, ~] = read(src,src.ScansAvailableFcnCount,"OutputFormat","Matrix");
voltage = mean(d(:,1));
app.VoltageEditField.Value = voltage;
app.LoadNEditField.Value = voltage * 4.19; %* 10497;
load =app.LoadNEditField.Value ;
app.VoltageLEditField.Value = mean(d(:,2));
distance = (app.VoltageLEditField.Value – 0.7966) * 4.51;
app.DistancemmEditField.Value = distance;
% Append data to arrays
app.timeData = [app.timeData; datetime(‘now’)];
app.loadData = [app.loadData; load];
app.distanceData = [app.distanceData; distance];
% Plot all data
yyaxis(app.UIAxes, ‘left’);
app.f1= plot(app.UIAxes, app.timeData, app.loadData);
ylabel(app.UIAxes, ‘Load (N)’);
yyaxis(app.UIAxes, ‘right’);
app.f2= plot(app.UIAxes, app.timeData, app.distanceData, ‘r’);
ylabel(app.UIAxes, ‘Displacement (mm)’);
xlabel(app.UIAxes, ‘Time’);
app.UIAxes.XGrid = ‘on’;
app.UIAxes.YGrid = ‘on’;
%{
plot(app.UIAxes, app.timeData, app.loadData, ‘b’, app.timeData, app.distanceData, ‘r’);
xlabel(app.UIAxes, ‘Time’);
ylabel(app.UIAxes, ‘Load (N) / Distance (mm)’);
legend(app.UIAxes, ‘Load’, ‘Distance’);
%}
end
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Switch
function SwitchValueChanged(app, event)
value = app.Switch.Value;
if strcmp(value,"On")
app.Lamp.Color = ‘g’;
app.dq = daq("ni");
app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
ch1 = addinput(app.dq, ‘Dev1’, ‘ai0′,’Voltage’);
ch2 = addinput(app.dq, ‘Dev1’, ‘ai1′,’Voltage’);
app.dq.Rate = app.R;
app.dq.UserData = [0 0];
start(app.dq,"Continuous");
else
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
app.Lamp.Color = ‘r’;
% delete(app.f1);
%
% delete(app.f2);
removechannel(app.dq,1:length(app.dq))
% start(app.dq,"Continuous");
% removechannel(app.dq,2)
% daqreset
end
end
% Button pushed function: SAVEDATAButton
function SAVEDATAButtonPushed(app, event)
% Prompt the user to choose a filename and location for saving the data
[filename, filepath] = uiputfile(‘*.csv’, ‘Save Data As’);
if isequal(filename,0) || isequal(filepath,0)
% User canceled the operation
return;
end
% Combine the filename and path
fullpath = fullfile(filepath, filename);
% Open or create the CSV file
fid = fopen(fullpath, ‘w’);
% Write headers to the CSV file
fprintf(fid, ‘Time,Load (N),Displacement (mm)n’);
% Write data to the CSV file
for i = 1:numel(app.timeData)
fprintf(fid, ‘%s,%f,%fn’, …
datestr(app.timeData(i)), …
app.loadData(i), …
app.distanceData(i));
end
% Close the file
fclose(fid);
end
% Callback function
function SystemLogSizeChanged(app, event)
% position = app.SystemLog.Position;
% if strcmp(app.Lamp.Color,’g’)
%
end
% Button pushed function: CleardataButton
function CleardataButtonPushed(app, event)
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
% Clear the session and channels.
% app.timeData = [app.timeData; datetime(‘now’)];
% app.loadData = [app.loadData; app.load];
% app.distanceData = [app.distanceData; app.distance];
delete(app.f1);
delete (‘app.timeData’)
delete (‘app.distanceData’)
delete (‘app.loadData’)
delete(app.f2);
% daqreset
% start(app.dq);
% app.dq
% stop(app.dq);
% cla(app.load,"reset");
% delete (app.load);
% cla(app.distance,"reset");
% delete(app.distance);
% cla(app.UIAxes);
% cla()
% delete(app.dq);
% delete(app.distance);
% delete(app.UIAxes)
% cla(app.UIAxes,"reset");
% app.dq.release(‘ni’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 1051 699];
app.UIFigure.Name = ‘MATLAB App’;
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 0 1051 699];
% Create Tab
app.Tab = uitab(app.TabGroup);
app.Tab.Title = ‘Tab’;
% Create UIAxes
app.UIAxes = uiaxes(app.Tab);
xlabel(app.UIAxes, ‘Displacement (mm)’)
ylabel(app.UIAxes, ‘Force (N)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.YGrid = ‘on’;
app.UIAxes.Position = [15 26 828 505];
% Create SwitchLabel
app.SwitchLabel = uilabel(app.Tab);
app.SwitchLabel.HorizontalAlignment = ‘center’;
app.SwitchLabel.Position = [40 599 40 22];
app.SwitchLabel.Text = ‘Switch’;
% Create Switch
app.Switch = uiswitch(app.Tab, ‘slider’);
app.Switch.ValueChangedFcn = createCallbackFcn(app, @SwitchValueChanged, true);
app.Switch.Position = [37 636 45 20];
% Create LampLabel
app.LampLabel = uilabel(app.Tab);
app.LampLabel.HorizontalAlignment = ‘right’;
app.LampLabel.Position = [25 562 35 22];
app.LampLabel.Text = ‘Lamp’;
% Create Lamp
app.Lamp = uilamp(app.Tab);
app.Lamp.Position = [75 562 20 20];
app.Lamp.Color = [1 0 0];
% Create SAVEDATAButton
app.SAVEDATAButton = uibutton(app.Tab, ‘push’);
app.SAVEDATAButton.ButtonPushedFcn = createCallbackFcn(app, @SAVEDATAButtonPushed, true);
app.SAVEDATAButton.Position = [940 25 100 23];
app.SAVEDATAButton.Text = ‘SAVE DATA’;
% Create VoltageEditFieldLabel
app.VoltageEditFieldLabel = uilabel(app.Tab);
app.VoltageEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageEditFieldLabel.Position = [878 226 46 22];
app.VoltageEditFieldLabel.Text = ‘Voltage’;
% Create VoltageEditField
app.VoltageEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageEditField.Position = [939 226 100 22];
% Create LoadNEditFieldLabel
app.LoadNEditFieldLabel = uilabel(app.Tab);
app.LoadNEditFieldLabel.HorizontalAlignment = ‘right’;
app.LoadNEditFieldLabel.Position = [872 133 52 22];
app.LoadNEditFieldLabel.Text = ‘Load (N)’;
% Create LoadNEditField
app.LoadNEditField = uieditfield(app.Tab, ‘numeric’);
app.LoadNEditField.Position = [939 133 100 22];
% Create VoltageLEditFieldLabel
app.VoltageLEditFieldLabel = uilabel(app.Tab);
app.VoltageLEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageLEditFieldLabel.Position = [861 188 63 22];
app.VoltageLEditFieldLabel.Text = ‘Voltage (L)’;
% Create VoltageLEditField
app.VoltageLEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageLEditField.Position = [939 188 100 22];
% Create DistancemmEditFieldLabel
app.DistancemmEditFieldLabel = uilabel(app.Tab);
app.DistancemmEditFieldLabel.HorizontalAlignment = ‘right’;
app.DistancemmEditFieldLabel.Position = [841 82 83 22];
app.DistancemmEditFieldLabel.Text = ‘Distance (mm)’;
% Create DistancemmEditField
app.DistancemmEditField = uieditfield(app.Tab, ‘numeric’);
app.DistancemmEditField.Position = [939 82 100 22];
% Create CleardataButton
app.CleardataButton = uibutton(app.Tab, ‘push’);
app.CleardataButton.ButtonPushedFcn = createCallbackFcn(app, @CleardataButtonPushed, true);
app.CleardataButton.Position = [938 280 100 23];
app.CleardataButton.Text = ‘Clear data’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app2
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
endHope you all well, i have GUI app which is getting data from national instrument and give back live plot after trun switch on and when switch is off the recorded data wil stop and real time data will stop, however i am trying to intesert another button to clear the previous or delete them from store array however it won’t happened i tried clear func and clf to remove plot and delete the array nothing working i will place the code blow and screen shot of the app design if you could help me to solve this i would be supre greatfull to you what i want is that the previouse data from block 1 and 2 get deleted after clear data button is clicked
classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Tab matlab.ui.container.Tab
CleardataButton matlab.ui.control.Button
DistancemmEditField matlab.ui.control.NumericEditField
DistancemmEditFieldLabel matlab.ui.control.Label
VoltageLEditField matlab.ui.control.NumericEditField
VoltageLEditFieldLabel matlab.ui.control.Label
LoadNEditField matlab.ui.control.NumericEditField
LoadNEditFieldLabel matlab.ui.control.Label
VoltageEditField matlab.ui.control.NumericEditField
VoltageEditFieldLabel matlab.ui.control.Label
SAVEDATAButton matlab.ui.control.Button
Lamp matlab.ui.control.Lamp
LampLabel matlab.ui.control.Label
Switch matlab.ui.control.Switch
SwitchLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
dq = daq("ni"); % Create a DataAcquisition object.
R = 5000;% Description
% % Arrays to store data for plotting
% timeData = [];
% loadData = [];
% distanceData = [];
end
properties (Access = public)
voltage
distance
load
f1
f2
timeData = [];
loadData = [];
distanceData = [];
end
methods (Access = public)
%
function getdat(app,src,~)
[d, ~] = read(src,src.ScansAvailableFcnCount,"OutputFormat","Matrix");
voltage = mean(d(:,1));
app.VoltageEditField.Value = voltage;
app.LoadNEditField.Value = voltage * 4.19; %* 10497;
load =app.LoadNEditField.Value ;
app.VoltageLEditField.Value = mean(d(:,2));
distance = (app.VoltageLEditField.Value – 0.7966) * 4.51;
app.DistancemmEditField.Value = distance;
% Append data to arrays
app.timeData = [app.timeData; datetime(‘now’)];
app.loadData = [app.loadData; load];
app.distanceData = [app.distanceData; distance];
% Plot all data
yyaxis(app.UIAxes, ‘left’);
app.f1= plot(app.UIAxes, app.timeData, app.loadData);
ylabel(app.UIAxes, ‘Load (N)’);
yyaxis(app.UIAxes, ‘right’);
app.f2= plot(app.UIAxes, app.timeData, app.distanceData, ‘r’);
ylabel(app.UIAxes, ‘Displacement (mm)’);
xlabel(app.UIAxes, ‘Time’);
app.UIAxes.XGrid = ‘on’;
app.UIAxes.YGrid = ‘on’;
%{
plot(app.UIAxes, app.timeData, app.loadData, ‘b’, app.timeData, app.distanceData, ‘r’);
xlabel(app.UIAxes, ‘Time’);
ylabel(app.UIAxes, ‘Load (N) / Distance (mm)’);
legend(app.UIAxes, ‘Load’, ‘Distance’);
%}
end
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Switch
function SwitchValueChanged(app, event)
value = app.Switch.Value;
if strcmp(value,"On")
app.Lamp.Color = ‘g’;
app.dq = daq("ni");
app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
ch1 = addinput(app.dq, ‘Dev1’, ‘ai0′,’Voltage’);
ch2 = addinput(app.dq, ‘Dev1’, ‘ai1′,’Voltage’);
app.dq.Rate = app.R;
app.dq.UserData = [0 0];
start(app.dq,"Continuous");
else
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
app.Lamp.Color = ‘r’;
% delete(app.f1);
%
% delete(app.f2);
removechannel(app.dq,1:length(app.dq))
% start(app.dq,"Continuous");
% removechannel(app.dq,2)
% daqreset
end
end
% Button pushed function: SAVEDATAButton
function SAVEDATAButtonPushed(app, event)
% Prompt the user to choose a filename and location for saving the data
[filename, filepath] = uiputfile(‘*.csv’, ‘Save Data As’);
if isequal(filename,0) || isequal(filepath,0)
% User canceled the operation
return;
end
% Combine the filename and path
fullpath = fullfile(filepath, filename);
% Open or create the CSV file
fid = fopen(fullpath, ‘w’);
% Write headers to the CSV file
fprintf(fid, ‘Time,Load (N),Displacement (mm)n’);
% Write data to the CSV file
for i = 1:numel(app.timeData)
fprintf(fid, ‘%s,%f,%fn’, …
datestr(app.timeData(i)), …
app.loadData(i), …
app.distanceData(i));
end
% Close the file
fclose(fid);
end
% Callback function
function SystemLogSizeChanged(app, event)
% position = app.SystemLog.Position;
% if strcmp(app.Lamp.Color,’g’)
%
end
% Button pushed function: CleardataButton
function CleardataButtonPushed(app, event)
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
% Clear the session and channels.
% app.timeData = [app.timeData; datetime(‘now’)];
% app.loadData = [app.loadData; app.load];
% app.distanceData = [app.distanceData; app.distance];
delete(app.f1);
delete (‘app.timeData’)
delete (‘app.distanceData’)
delete (‘app.loadData’)
delete(app.f2);
% daqreset
% start(app.dq);
% app.dq
% stop(app.dq);
% cla(app.load,"reset");
% delete (app.load);
% cla(app.distance,"reset");
% delete(app.distance);
% cla(app.UIAxes);
% cla()
% delete(app.dq);
% delete(app.distance);
% delete(app.UIAxes)
% cla(app.UIAxes,"reset");
% app.dq.release(‘ni’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 1051 699];
app.UIFigure.Name = ‘MATLAB App’;
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 0 1051 699];
% Create Tab
app.Tab = uitab(app.TabGroup);
app.Tab.Title = ‘Tab’;
% Create UIAxes
app.UIAxes = uiaxes(app.Tab);
xlabel(app.UIAxes, ‘Displacement (mm)’)
ylabel(app.UIAxes, ‘Force (N)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.YGrid = ‘on’;
app.UIAxes.Position = [15 26 828 505];
% Create SwitchLabel
app.SwitchLabel = uilabel(app.Tab);
app.SwitchLabel.HorizontalAlignment = ‘center’;
app.SwitchLabel.Position = [40 599 40 22];
app.SwitchLabel.Text = ‘Switch’;
% Create Switch
app.Switch = uiswitch(app.Tab, ‘slider’);
app.Switch.ValueChangedFcn = createCallbackFcn(app, @SwitchValueChanged, true);
app.Switch.Position = [37 636 45 20];
% Create LampLabel
app.LampLabel = uilabel(app.Tab);
app.LampLabel.HorizontalAlignment = ‘right’;
app.LampLabel.Position = [25 562 35 22];
app.LampLabel.Text = ‘Lamp’;
% Create Lamp
app.Lamp = uilamp(app.Tab);
app.Lamp.Position = [75 562 20 20];
app.Lamp.Color = [1 0 0];
% Create SAVEDATAButton
app.SAVEDATAButton = uibutton(app.Tab, ‘push’);
app.SAVEDATAButton.ButtonPushedFcn = createCallbackFcn(app, @SAVEDATAButtonPushed, true);
app.SAVEDATAButton.Position = [940 25 100 23];
app.SAVEDATAButton.Text = ‘SAVE DATA’;
% Create VoltageEditFieldLabel
app.VoltageEditFieldLabel = uilabel(app.Tab);
app.VoltageEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageEditFieldLabel.Position = [878 226 46 22];
app.VoltageEditFieldLabel.Text = ‘Voltage’;
% Create VoltageEditField
app.VoltageEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageEditField.Position = [939 226 100 22];
% Create LoadNEditFieldLabel
app.LoadNEditFieldLabel = uilabel(app.Tab);
app.LoadNEditFieldLabel.HorizontalAlignment = ‘right’;
app.LoadNEditFieldLabel.Position = [872 133 52 22];
app.LoadNEditFieldLabel.Text = ‘Load (N)’;
% Create LoadNEditField
app.LoadNEditField = uieditfield(app.Tab, ‘numeric’);
app.LoadNEditField.Position = [939 133 100 22];
% Create VoltageLEditFieldLabel
app.VoltageLEditFieldLabel = uilabel(app.Tab);
app.VoltageLEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageLEditFieldLabel.Position = [861 188 63 22];
app.VoltageLEditFieldLabel.Text = ‘Voltage (L)’;
% Create VoltageLEditField
app.VoltageLEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageLEditField.Position = [939 188 100 22];
% Create DistancemmEditFieldLabel
app.DistancemmEditFieldLabel = uilabel(app.Tab);
app.DistancemmEditFieldLabel.HorizontalAlignment = ‘right’;
app.DistancemmEditFieldLabel.Position = [841 82 83 22];
app.DistancemmEditFieldLabel.Text = ‘Distance (mm)’;
% Create DistancemmEditField
app.DistancemmEditField = uieditfield(app.Tab, ‘numeric’);
app.DistancemmEditField.Position = [939 82 100 22];
% Create CleardataButton
app.CleardataButton = uibutton(app.Tab, ‘push’);
app.CleardataButton.ButtonPushedFcn = createCallbackFcn(app, @CleardataButtonPushed, true);
app.CleardataButton.Position = [938 280 100 23];
app.CleardataButton.Text = ‘Clear data’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app2
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end Hope you all well, i have GUI app which is getting data from national instrument and give back live plot after trun switch on and when switch is off the recorded data wil stop and real time data will stop, however i am trying to intesert another button to clear the previous or delete them from store array however it won’t happened i tried clear func and clf to remove plot and delete the array nothing working i will place the code blow and screen shot of the app design if you could help me to solve this i would be supre greatfull to you what i want is that the previouse data from block 1 and 2 get deleted after clear data button is clicked
classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Tab matlab.ui.container.Tab
CleardataButton matlab.ui.control.Button
DistancemmEditField matlab.ui.control.NumericEditField
DistancemmEditFieldLabel matlab.ui.control.Label
VoltageLEditField matlab.ui.control.NumericEditField
VoltageLEditFieldLabel matlab.ui.control.Label
LoadNEditField matlab.ui.control.NumericEditField
LoadNEditFieldLabel matlab.ui.control.Label
VoltageEditField matlab.ui.control.NumericEditField
VoltageEditFieldLabel matlab.ui.control.Label
SAVEDATAButton matlab.ui.control.Button
Lamp matlab.ui.control.Lamp
LampLabel matlab.ui.control.Label
Switch matlab.ui.control.Switch
SwitchLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
dq = daq("ni"); % Create a DataAcquisition object.
R = 5000;% Description
% % Arrays to store data for plotting
% timeData = [];
% loadData = [];
% distanceData = [];
end
properties (Access = public)
voltage
distance
load
f1
f2
timeData = [];
loadData = [];
distanceData = [];
end
methods (Access = public)
%
function getdat(app,src,~)
[d, ~] = read(src,src.ScansAvailableFcnCount,"OutputFormat","Matrix");
voltage = mean(d(:,1));
app.VoltageEditField.Value = voltage;
app.LoadNEditField.Value = voltage * 4.19; %* 10497;
load =app.LoadNEditField.Value ;
app.VoltageLEditField.Value = mean(d(:,2));
distance = (app.VoltageLEditField.Value – 0.7966) * 4.51;
app.DistancemmEditField.Value = distance;
% Append data to arrays
app.timeData = [app.timeData; datetime(‘now’)];
app.loadData = [app.loadData; load];
app.distanceData = [app.distanceData; distance];
% Plot all data
yyaxis(app.UIAxes, ‘left’);
app.f1= plot(app.UIAxes, app.timeData, app.loadData);
ylabel(app.UIAxes, ‘Load (N)’);
yyaxis(app.UIAxes, ‘right’);
app.f2= plot(app.UIAxes, app.timeData, app.distanceData, ‘r’);
ylabel(app.UIAxes, ‘Displacement (mm)’);
xlabel(app.UIAxes, ‘Time’);
app.UIAxes.XGrid = ‘on’;
app.UIAxes.YGrid = ‘on’;
%{
plot(app.UIAxes, app.timeData, app.loadData, ‘b’, app.timeData, app.distanceData, ‘r’);
xlabel(app.UIAxes, ‘Time’);
ylabel(app.UIAxes, ‘Load (N) / Distance (mm)’);
legend(app.UIAxes, ‘Load’, ‘Distance’);
%}
end
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Switch
function SwitchValueChanged(app, event)
value = app.Switch.Value;
if strcmp(value,"On")
app.Lamp.Color = ‘g’;
app.dq = daq("ni");
app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
ch1 = addinput(app.dq, ‘Dev1’, ‘ai0′,’Voltage’);
ch2 = addinput(app.dq, ‘Dev1’, ‘ai1′,’Voltage’);
app.dq.Rate = app.R;
app.dq.UserData = [0 0];
start(app.dq,"Continuous");
else
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
app.Lamp.Color = ‘r’;
% delete(app.f1);
%
% delete(app.f2);
removechannel(app.dq,1:length(app.dq))
% start(app.dq,"Continuous");
% removechannel(app.dq,2)
% daqreset
end
end
% Button pushed function: SAVEDATAButton
function SAVEDATAButtonPushed(app, event)
% Prompt the user to choose a filename and location for saving the data
[filename, filepath] = uiputfile(‘*.csv’, ‘Save Data As’);
if isequal(filename,0) || isequal(filepath,0)
% User canceled the operation
return;
end
% Combine the filename and path
fullpath = fullfile(filepath, filename);
% Open or create the CSV file
fid = fopen(fullpath, ‘w’);
% Write headers to the CSV file
fprintf(fid, ‘Time,Load (N),Displacement (mm)n’);
% Write data to the CSV file
for i = 1:numel(app.timeData)
fprintf(fid, ‘%s,%f,%fn’, …
datestr(app.timeData(i)), …
app.loadData(i), …
app.distanceData(i));
end
% Close the file
fclose(fid);
end
% Callback function
function SystemLogSizeChanged(app, event)
% position = app.SystemLog.Position;
% if strcmp(app.Lamp.Color,’g’)
%
end
% Button pushed function: CleardataButton
function CleardataButtonPushed(app, event)
% app.dq.ScansAvailableFcn = @(src,event) getdat(app, src, event);
stop(app.dq);
% Clear the session and channels.
% app.timeData = [app.timeData; datetime(‘now’)];
% app.loadData = [app.loadData; app.load];
% app.distanceData = [app.distanceData; app.distance];
delete(app.f1);
delete (‘app.timeData’)
delete (‘app.distanceData’)
delete (‘app.loadData’)
delete(app.f2);
% daqreset
% start(app.dq);
% app.dq
% stop(app.dq);
% cla(app.load,"reset");
% delete (app.load);
% cla(app.distance,"reset");
% delete(app.distance);
% cla(app.UIAxes);
% cla()
% delete(app.dq);
% delete(app.distance);
% delete(app.UIAxes)
% cla(app.UIAxes,"reset");
% app.dq.release(‘ni’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 1051 699];
app.UIFigure.Name = ‘MATLAB App’;
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 0 1051 699];
% Create Tab
app.Tab = uitab(app.TabGroup);
app.Tab.Title = ‘Tab’;
% Create UIAxes
app.UIAxes = uiaxes(app.Tab);
xlabel(app.UIAxes, ‘Displacement (mm)’)
ylabel(app.UIAxes, ‘Force (N)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.YGrid = ‘on’;
app.UIAxes.Position = [15 26 828 505];
% Create SwitchLabel
app.SwitchLabel = uilabel(app.Tab);
app.SwitchLabel.HorizontalAlignment = ‘center’;
app.SwitchLabel.Position = [40 599 40 22];
app.SwitchLabel.Text = ‘Switch’;
% Create Switch
app.Switch = uiswitch(app.Tab, ‘slider’);
app.Switch.ValueChangedFcn = createCallbackFcn(app, @SwitchValueChanged, true);
app.Switch.Position = [37 636 45 20];
% Create LampLabel
app.LampLabel = uilabel(app.Tab);
app.LampLabel.HorizontalAlignment = ‘right’;
app.LampLabel.Position = [25 562 35 22];
app.LampLabel.Text = ‘Lamp’;
% Create Lamp
app.Lamp = uilamp(app.Tab);
app.Lamp.Position = [75 562 20 20];
app.Lamp.Color = [1 0 0];
% Create SAVEDATAButton
app.SAVEDATAButton = uibutton(app.Tab, ‘push’);
app.SAVEDATAButton.ButtonPushedFcn = createCallbackFcn(app, @SAVEDATAButtonPushed, true);
app.SAVEDATAButton.Position = [940 25 100 23];
app.SAVEDATAButton.Text = ‘SAVE DATA’;
% Create VoltageEditFieldLabel
app.VoltageEditFieldLabel = uilabel(app.Tab);
app.VoltageEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageEditFieldLabel.Position = [878 226 46 22];
app.VoltageEditFieldLabel.Text = ‘Voltage’;
% Create VoltageEditField
app.VoltageEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageEditField.Position = [939 226 100 22];
% Create LoadNEditFieldLabel
app.LoadNEditFieldLabel = uilabel(app.Tab);
app.LoadNEditFieldLabel.HorizontalAlignment = ‘right’;
app.LoadNEditFieldLabel.Position = [872 133 52 22];
app.LoadNEditFieldLabel.Text = ‘Load (N)’;
% Create LoadNEditField
app.LoadNEditField = uieditfield(app.Tab, ‘numeric’);
app.LoadNEditField.Position = [939 133 100 22];
% Create VoltageLEditFieldLabel
app.VoltageLEditFieldLabel = uilabel(app.Tab);
app.VoltageLEditFieldLabel.HorizontalAlignment = ‘right’;
app.VoltageLEditFieldLabel.Position = [861 188 63 22];
app.VoltageLEditFieldLabel.Text = ‘Voltage (L)’;
% Create VoltageLEditField
app.VoltageLEditField = uieditfield(app.Tab, ‘numeric’);
app.VoltageLEditField.Position = [939 188 100 22];
% Create DistancemmEditFieldLabel
app.DistancemmEditFieldLabel = uilabel(app.Tab);
app.DistancemmEditFieldLabel.HorizontalAlignment = ‘right’;
app.DistancemmEditFieldLabel.Position = [841 82 83 22];
app.DistancemmEditFieldLabel.Text = ‘Distance (mm)’;
% Create DistancemmEditField
app.DistancemmEditField = uieditfield(app.Tab, ‘numeric’);
app.DistancemmEditField.Position = [939 82 100 22];
% Create CleardataButton
app.CleardataButton = uibutton(app.Tab, ‘push’);
app.CleardataButton.ButtonPushedFcn = createCallbackFcn(app, @CleardataButtonPushed, true);
app.CleardataButton.Position = [938 280 100 23];
app.CleardataButton.Text = ‘Clear data’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app2
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end matrix array, replacement, real time, gui, clear data, matrix, data MATLAB Answers — New Questions
Why does my matlab code cannot detect the number of periods in a specific time range
I have developed a matlab code which imports pNRF Files that contain a measurement signal of light distance of a wheel surface in order to detect the number of cracks on that surface. There are in the file 3 signals, 2 rotary encoder signals and one light distance signal.
The Code does mostly what I want it to do:
It can import the Data accurately and successfully.
It can plot all the 3 signals
It can detect the cracks automatically using a threshold
One thing thats important and that the code is doing wrong, is that it detects the wrong number of the periods in the time range where a crack is being detected. (See the following picture, the back rectangles are the Cracks detected).
Now what I would like to do is to calculate the number of the Periods on the Signal Ch B1 (increment Encoder A) in the time where a crack is being detected. In this example the number of the periods is about 5,2 Periods of the first Crack and about nearly 1 Period of the second crack.
This is a substract of the 200line Code that i have to determine how many cracks I have:
% Zusammenfassung der Risse anzeigen
disp(‘Anzahl der detektierten Risse:’);
disp(numCracks);
disp(‘Breite der detektierten Risse in Inkrementen und Mikrometern:’);
for i = 1:numCracks
rissIndizes = risseGruppen.PixelIdxList{i};
Crackstart = min(rissIndizes);
Crackstart = max(rissIndizes);
Periods_Yellow_Signal = locs_gelb(locs_gelb >= Crackstart & locs_gelb <= Crackend);
CracksthicknessinPeriods = length(Periods_Yellow_Signal);
rissBreiteMicrometer = CracksthicknessinPeriods * INC_TO_MICROMETER;
fprintf(‘Crack %d: Thickness = %d Periods, %.2f Micrometer (Signal: Ch B1_A)n’, i, rissBreiteInkrement, rissBreiteMicrometer);
fprintf(‘Number of Periods: %dn’, rissBreiteInkrement);
end
What am I doing wrong here?
I would so thankful for any help! Thanks a lot in advance.I have developed a matlab code which imports pNRF Files that contain a measurement signal of light distance of a wheel surface in order to detect the number of cracks on that surface. There are in the file 3 signals, 2 rotary encoder signals and one light distance signal.
The Code does mostly what I want it to do:
It can import the Data accurately and successfully.
It can plot all the 3 signals
It can detect the cracks automatically using a threshold
One thing thats important and that the code is doing wrong, is that it detects the wrong number of the periods in the time range where a crack is being detected. (See the following picture, the back rectangles are the Cracks detected).
Now what I would like to do is to calculate the number of the Periods on the Signal Ch B1 (increment Encoder A) in the time where a crack is being detected. In this example the number of the periods is about 5,2 Periods of the first Crack and about nearly 1 Period of the second crack.
This is a substract of the 200line Code that i have to determine how many cracks I have:
% Zusammenfassung der Risse anzeigen
disp(‘Anzahl der detektierten Risse:’);
disp(numCracks);
disp(‘Breite der detektierten Risse in Inkrementen und Mikrometern:’);
for i = 1:numCracks
rissIndizes = risseGruppen.PixelIdxList{i};
Crackstart = min(rissIndizes);
Crackstart = max(rissIndizes);
Periods_Yellow_Signal = locs_gelb(locs_gelb >= Crackstart & locs_gelb <= Crackend);
CracksthicknessinPeriods = length(Periods_Yellow_Signal);
rissBreiteMicrometer = CracksthicknessinPeriods * INC_TO_MICROMETER;
fprintf(‘Crack %d: Thickness = %d Periods, %.2f Micrometer (Signal: Ch B1_A)n’, i, rissBreiteInkrement, rissBreiteMicrometer);
fprintf(‘Number of Periods: %dn’, rissBreiteInkrement);
end
What am I doing wrong here?
I would so thankful for any help! Thanks a lot in advance. I have developed a matlab code which imports pNRF Files that contain a measurement signal of light distance of a wheel surface in order to detect the number of cracks on that surface. There are in the file 3 signals, 2 rotary encoder signals and one light distance signal.
The Code does mostly what I want it to do:
It can import the Data accurately and successfully.
It can plot all the 3 signals
It can detect the cracks automatically using a threshold
One thing thats important and that the code is doing wrong, is that it detects the wrong number of the periods in the time range where a crack is being detected. (See the following picture, the back rectangles are the Cracks detected).
Now what I would like to do is to calculate the number of the Periods on the Signal Ch B1 (increment Encoder A) in the time where a crack is being detected. In this example the number of the periods is about 5,2 Periods of the first Crack and about nearly 1 Period of the second crack.
This is a substract of the 200line Code that i have to determine how many cracks I have:
% Zusammenfassung der Risse anzeigen
disp(‘Anzahl der detektierten Risse:’);
disp(numCracks);
disp(‘Breite der detektierten Risse in Inkrementen und Mikrometern:’);
for i = 1:numCracks
rissIndizes = risseGruppen.PixelIdxList{i};
Crackstart = min(rissIndizes);
Crackstart = max(rissIndizes);
Periods_Yellow_Signal = locs_gelb(locs_gelb >= Crackstart & locs_gelb <= Crackend);
CracksthicknessinPeriods = length(Periods_Yellow_Signal);
rissBreiteMicrometer = CracksthicknessinPeriods * INC_TO_MICROMETER;
fprintf(‘Crack %d: Thickness = %d Periods, %.2f Micrometer (Signal: Ch B1_A)n’, i, rissBreiteInkrement, rissBreiteMicrometer);
fprintf(‘Number of Periods: %dn’, rissBreiteInkrement);
end
What am I doing wrong here?
I would so thankful for any help! Thanks a lot in advance. periods, frequency, signal, signal processing, cracks, thickness MATLAB Answers — New Questions
Worker crashed while executing code
Warning: 1 worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt to run the code again on the remaining workers of the pool, unless an spmd block has run. View the crash dump files to determine what caused the workers to crash.
As I have the home licenses I’m not sure what to do with the error above. The script is training a Trebagger model with parallel turned on. It does use a lot of memory but still fits within the 32GB I have. The log is :-
——————————————————————————–
abort() detected at 2024-06-09 14:55:26 +0100
——————————————————————————–
Configuration:
Crash Decoding : Disabled – No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA GeForce RTX 3060 Ti Version 32.0.15.5599 (2024-6-1)
Graphics card 2 : Intel Corporation ( 0x8086 ) Intel(R) UHD Graphics 770 Version 31.0.101.4577 (2023-7-24)
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 5834768
MATLAB Root : C:Program FilesMATLABR2024a
MATLAB Version : 24.1.0.2603908 (R2024a) Update 3
OpenGL : hardware
Operating System : Microsoft Windows 11 Home
Process ID : 24484
Processor ID : x86 Family 6 Model 151 Stepping 2, GenuineIntel
Session Key : 21d9c0b4-6172-4c58-b200-f26395bd30e7
Window System : Version 10.0 (Build 22631)
Fault Count: 1
Abnormal termination:
abort()
Current Thread: ” id 15936
Register State (captured):
RAX = 00007ffc736e7208 RBX = 00007ffc736e7208
RCX = 0000000b268f8790 RDX = 00007ffc736918f0
RSP = 0000000b268f86d0 RBP = 0000000b268f9460
RSI = 0000000000000000 RDI = 00007ffc736e7208
R8 = 0000000000000003 R9 = 0000000b268f8648
R10 = 0000000000000014 R11 = 0000000000000000
R12 = 0000000b268f9368 R13 = 0000000000000000
R14 = 00007ffc736d7138 R15 = 0000000b268f8da0
RIP = 00007ffc735d1c8a EFL = 00000202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (captured):
[ 0] 0x00007ffc735cb093 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00045203 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffc735c94c8 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00038088 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffc735cd90f C:Program FilesMATLABR2024abinwin64libmwfl.dll+00055567 foundation::core::diag::symbols::getSymbolAddress+00009855
[ 3] 0x00007ffc735d07d7 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00067543 foundation::core::diag::is_terminate_message_enabled+00000503
[ 4] 0x00007ffbf21c1868 C:Program FilesMATLABR2024abinwin64mcr.dll+00792680 mnFullExitFcn+00034808
[ 5] 0x00007ffbf21c10cd C:Program FilesMATLABR2024abinwin64mcr.dll+00790733 mnFullExitFcn+00032861
[ 6] 0x00007ffbf21bd315 C:Program FilesMATLABR2024abinwin64mcr.dll+00774933 mnFullExitFcn+00017061
[ 7] 0x00007ffbf21bed5f C:Program FilesMATLABR2024abinwin64mcr.dll+00781663 mnFullExitFcn+00023791
[ 8] 0x00007ffcb8f7e6d5 C:WINDOWSSystem32ucrtbase.dll+00517845 raise+00000485
[ 9] 0x00007ffcb8f7f6e1 C:WINDOWSSystem32ucrtbase.dll+00521953 abort+00000049
[ 10] 0x00007ffcb8f7ee19 C:WINDOWSSystem32ucrtbase.dll+00519705 terminate+00000041
[ 11] 0x00007ffcb3ea1aab C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00006827 _NLG_Return2+00002395
[ 12] 0x00007ffcb3ea2317 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00008983 _NLG_Return2+00004551
[ 13] 0x00007ffcb3ea237a C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00009082 _NLG_Return2+00004650
[ 14] 0x00007ffcb3ea4159 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00016729 _CxxFrameHandler4+00000169
[ 15] 0x00007ffcbb9549ff C:WINDOWSSYSTEM32ntdll.dll+00674303 _chkstk+00000303
[ 16] 0x00007ffcbb8ce466 C:WINDOWSSYSTEM32ntdll.dll+00124006 RtlFindCharInUnicodeString+00002710
[ 17] 0x00007ffcbb904465 C:WINDOWSSYSTEM32ntdll.dll+00345189 RtlRaiseException+00000405
[ 18] 0x00007ffcb90f543c C:WINDOWSSystem32KERNELBASE.dll+00414780 RaiseException+00000108
[ 19] 0x00007ffcb3ea2793 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00010131 _NLG_Return2+00005699
[ 20] 0x00007ffcbb954246 C:WINDOWSSYSTEM32ntdll.dll+00672326 RtlCaptureContext2+00001190
[ 21] 0x00007ffbeadd968a C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00104074 mwboost::serialization::singleton_module::lock+00009098
[ 22] 0x00007ffbeadc4d6f C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00019823
[ 23] 0x00007ffcb8f29333 C:WINDOWSSystem32ucrtbase.dll+00168755 recalloc+00000163
[ 24] 0x00007ffcb9f0257d C:WINDOWSSystem32KERNEL32.DLL+00075133 BaseThreadInitThunk+00000029
[ 25] 0x00007ffcbb90aa48 C:WINDOWSSYSTEM32ntdll.dll+00371272 RtlUserThreadStart+00000040
It doesn’t always happen but I’d like to know if anyone has an idea why this might be happening and if it affects the training or not.Warning: 1 worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt to run the code again on the remaining workers of the pool, unless an spmd block has run. View the crash dump files to determine what caused the workers to crash.
As I have the home licenses I’m not sure what to do with the error above. The script is training a Trebagger model with parallel turned on. It does use a lot of memory but still fits within the 32GB I have. The log is :-
——————————————————————————–
abort() detected at 2024-06-09 14:55:26 +0100
——————————————————————————–
Configuration:
Crash Decoding : Disabled – No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA GeForce RTX 3060 Ti Version 32.0.15.5599 (2024-6-1)
Graphics card 2 : Intel Corporation ( 0x8086 ) Intel(R) UHD Graphics 770 Version 31.0.101.4577 (2023-7-24)
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 5834768
MATLAB Root : C:Program FilesMATLABR2024a
MATLAB Version : 24.1.0.2603908 (R2024a) Update 3
OpenGL : hardware
Operating System : Microsoft Windows 11 Home
Process ID : 24484
Processor ID : x86 Family 6 Model 151 Stepping 2, GenuineIntel
Session Key : 21d9c0b4-6172-4c58-b200-f26395bd30e7
Window System : Version 10.0 (Build 22631)
Fault Count: 1
Abnormal termination:
abort()
Current Thread: ” id 15936
Register State (captured):
RAX = 00007ffc736e7208 RBX = 00007ffc736e7208
RCX = 0000000b268f8790 RDX = 00007ffc736918f0
RSP = 0000000b268f86d0 RBP = 0000000b268f9460
RSI = 0000000000000000 RDI = 00007ffc736e7208
R8 = 0000000000000003 R9 = 0000000b268f8648
R10 = 0000000000000014 R11 = 0000000000000000
R12 = 0000000b268f9368 R13 = 0000000000000000
R14 = 00007ffc736d7138 R15 = 0000000b268f8da0
RIP = 00007ffc735d1c8a EFL = 00000202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (captured):
[ 0] 0x00007ffc735cb093 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00045203 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffc735c94c8 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00038088 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffc735cd90f C:Program FilesMATLABR2024abinwin64libmwfl.dll+00055567 foundation::core::diag::symbols::getSymbolAddress+00009855
[ 3] 0x00007ffc735d07d7 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00067543 foundation::core::diag::is_terminate_message_enabled+00000503
[ 4] 0x00007ffbf21c1868 C:Program FilesMATLABR2024abinwin64mcr.dll+00792680 mnFullExitFcn+00034808
[ 5] 0x00007ffbf21c10cd C:Program FilesMATLABR2024abinwin64mcr.dll+00790733 mnFullExitFcn+00032861
[ 6] 0x00007ffbf21bd315 C:Program FilesMATLABR2024abinwin64mcr.dll+00774933 mnFullExitFcn+00017061
[ 7] 0x00007ffbf21bed5f C:Program FilesMATLABR2024abinwin64mcr.dll+00781663 mnFullExitFcn+00023791
[ 8] 0x00007ffcb8f7e6d5 C:WINDOWSSystem32ucrtbase.dll+00517845 raise+00000485
[ 9] 0x00007ffcb8f7f6e1 C:WINDOWSSystem32ucrtbase.dll+00521953 abort+00000049
[ 10] 0x00007ffcb8f7ee19 C:WINDOWSSystem32ucrtbase.dll+00519705 terminate+00000041
[ 11] 0x00007ffcb3ea1aab C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00006827 _NLG_Return2+00002395
[ 12] 0x00007ffcb3ea2317 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00008983 _NLG_Return2+00004551
[ 13] 0x00007ffcb3ea237a C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00009082 _NLG_Return2+00004650
[ 14] 0x00007ffcb3ea4159 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00016729 _CxxFrameHandler4+00000169
[ 15] 0x00007ffcbb9549ff C:WINDOWSSYSTEM32ntdll.dll+00674303 _chkstk+00000303
[ 16] 0x00007ffcbb8ce466 C:WINDOWSSYSTEM32ntdll.dll+00124006 RtlFindCharInUnicodeString+00002710
[ 17] 0x00007ffcbb904465 C:WINDOWSSYSTEM32ntdll.dll+00345189 RtlRaiseException+00000405
[ 18] 0x00007ffcb90f543c C:WINDOWSSystem32KERNELBASE.dll+00414780 RaiseException+00000108
[ 19] 0x00007ffcb3ea2793 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00010131 _NLG_Return2+00005699
[ 20] 0x00007ffcbb954246 C:WINDOWSSYSTEM32ntdll.dll+00672326 RtlCaptureContext2+00001190
[ 21] 0x00007ffbeadd968a C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00104074 mwboost::serialization::singleton_module::lock+00009098
[ 22] 0x00007ffbeadc4d6f C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00019823
[ 23] 0x00007ffcb8f29333 C:WINDOWSSystem32ucrtbase.dll+00168755 recalloc+00000163
[ 24] 0x00007ffcb9f0257d C:WINDOWSSystem32KERNEL32.DLL+00075133 BaseThreadInitThunk+00000029
[ 25] 0x00007ffcbb90aa48 C:WINDOWSSYSTEM32ntdll.dll+00371272 RtlUserThreadStart+00000040
It doesn’t always happen but I’d like to know if anyone has an idea why this might be happening and if it affects the training or not. Warning: 1 worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt to run the code again on the remaining workers of the pool, unless an spmd block has run. View the crash dump files to determine what caused the workers to crash.
As I have the home licenses I’m not sure what to do with the error above. The script is training a Trebagger model with parallel turned on. It does use a lot of memory but still fits within the 32GB I have. The log is :-
——————————————————————————–
abort() detected at 2024-06-09 14:55:26 +0100
——————————————————————————–
Configuration:
Crash Decoding : Disabled – No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA GeForce RTX 3060 Ti Version 32.0.15.5599 (2024-6-1)
Graphics card 2 : Intel Corporation ( 0x8086 ) Intel(R) UHD Graphics 770 Version 31.0.101.4577 (2023-7-24)
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 5834768
MATLAB Root : C:Program FilesMATLABR2024a
MATLAB Version : 24.1.0.2603908 (R2024a) Update 3
OpenGL : hardware
Operating System : Microsoft Windows 11 Home
Process ID : 24484
Processor ID : x86 Family 6 Model 151 Stepping 2, GenuineIntel
Session Key : 21d9c0b4-6172-4c58-b200-f26395bd30e7
Window System : Version 10.0 (Build 22631)
Fault Count: 1
Abnormal termination:
abort()
Current Thread: ” id 15936
Register State (captured):
RAX = 00007ffc736e7208 RBX = 00007ffc736e7208
RCX = 0000000b268f8790 RDX = 00007ffc736918f0
RSP = 0000000b268f86d0 RBP = 0000000b268f9460
RSI = 0000000000000000 RDI = 00007ffc736e7208
R8 = 0000000000000003 R9 = 0000000b268f8648
R10 = 0000000000000014 R11 = 0000000000000000
R12 = 0000000b268f9368 R13 = 0000000000000000
R14 = 00007ffc736d7138 R15 = 0000000b268f8da0
RIP = 00007ffc735d1c8a EFL = 00000202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (captured):
[ 0] 0x00007ffc735cb093 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00045203 foundation::core::diag::thread_context::unspecified_bool+00000051
[ 1] 0x00007ffc735c94c8 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00038088 foundation::core::diag::stacktrace_base::capture+00000024
[ 2] 0x00007ffc735cd90f C:Program FilesMATLABR2024abinwin64libmwfl.dll+00055567 foundation::core::diag::symbols::getSymbolAddress+00009855
[ 3] 0x00007ffc735d07d7 C:Program FilesMATLABR2024abinwin64libmwfl.dll+00067543 foundation::core::diag::is_terminate_message_enabled+00000503
[ 4] 0x00007ffbf21c1868 C:Program FilesMATLABR2024abinwin64mcr.dll+00792680 mnFullExitFcn+00034808
[ 5] 0x00007ffbf21c10cd C:Program FilesMATLABR2024abinwin64mcr.dll+00790733 mnFullExitFcn+00032861
[ 6] 0x00007ffbf21bd315 C:Program FilesMATLABR2024abinwin64mcr.dll+00774933 mnFullExitFcn+00017061
[ 7] 0x00007ffbf21bed5f C:Program FilesMATLABR2024abinwin64mcr.dll+00781663 mnFullExitFcn+00023791
[ 8] 0x00007ffcb8f7e6d5 C:WINDOWSSystem32ucrtbase.dll+00517845 raise+00000485
[ 9] 0x00007ffcb8f7f6e1 C:WINDOWSSystem32ucrtbase.dll+00521953 abort+00000049
[ 10] 0x00007ffcb8f7ee19 C:WINDOWSSystem32ucrtbase.dll+00519705 terminate+00000041
[ 11] 0x00007ffcb3ea1aab C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00006827 _NLG_Return2+00002395
[ 12] 0x00007ffcb3ea2317 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00008983 _NLG_Return2+00004551
[ 13] 0x00007ffcb3ea237a C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00009082 _NLG_Return2+00004650
[ 14] 0x00007ffcb3ea4159 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00016729 _CxxFrameHandler4+00000169
[ 15] 0x00007ffcbb9549ff C:WINDOWSSYSTEM32ntdll.dll+00674303 _chkstk+00000303
[ 16] 0x00007ffcbb8ce466 C:WINDOWSSYSTEM32ntdll.dll+00124006 RtlFindCharInUnicodeString+00002710
[ 17] 0x00007ffcbb904465 C:WINDOWSSYSTEM32ntdll.dll+00345189 RtlRaiseException+00000405
[ 18] 0x00007ffcb90f543c C:WINDOWSSystem32KERNELBASE.dll+00414780 RaiseException+00000108
[ 19] 0x00007ffcb3ea2793 C:Program FilesMATLABR2024abinwin64VCRUNTIME140_1.dll+00010131 _NLG_Return2+00005699
[ 20] 0x00007ffcbb954246 C:WINDOWSSYSTEM32ntdll.dll+00672326 RtlCaptureContext2+00001190
[ 21] 0x00007ffbeadd968a C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00104074 mwboost::serialization::singleton_module::lock+00009098
[ 22] 0x00007ffbeadc4d6f C:Program FilesMATLABR2024abinwin64libmwparallelplrlicensing.dll+00019823
[ 23] 0x00007ffcb8f29333 C:WINDOWSSystem32ucrtbase.dll+00168755 recalloc+00000163
[ 24] 0x00007ffcb9f0257d C:WINDOWSSystem32KERNEL32.DLL+00075133 BaseThreadInitThunk+00000029
[ 25] 0x00007ffcbb90aa48 C:WINDOWSSYSTEM32ntdll.dll+00371272 RtlUserThreadStart+00000040
It doesn’t always happen but I’d like to know if anyone has an idea why this might be happening and if it affects the training or not. worker crash MATLAB Answers — New Questions
Approximation of Solution to Poisson-Equation via RBFs but with a change of Basis
Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max.Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max. Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max. rbf, radial basis function, interpolation, differential equations, kernel, approximation MATLAB Answers — New Questions
Accessing Fit Coefficients from Curve Fitting
Hello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data setHello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data set Hello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data set curve fitting, gaussian distribution MATLAB Answers — New Questions
i need code to generate key using PSO then adding the key to image
i need code to generate key using PSO then adding the key to image.i need code to generate key using PSO then adding the key to image. i need code to generate key using PSO then adding the key to image. image, image processing MATLAB Answers — New Questions