Find time offset that best lines up two position curves using appdesigner

6 visualizaciones (últimos 30 días)
% I have time histories of position (time, X, Y) from two different sources (KTM and RNET). Both sources have the target goin over about the same path, but % % there appears to be a time offset. I want to find the time offset to that best lines up the data for comparison.
properties (Access = private)
RNETTable
KTMTable
end
methods (Access = public)
% time histories from two sources
% are stored in tables
% SSDelta applies a time shift (dTime) to one time history of position
% (time, X, Y) and computes the sum of the square of the
% differences of the X and Y components
function SSD = SSDelta(app,dTime)
% apply time shift to one source
RSOD=app.RNETTable{:,'SOD'}+dTime;
% interpolate the X and Y data from RNET to times of the KTM
% since they are not synchronized and compute the sum of the
% squares of the differences
DX=interp1(RSOD(:),app.RNETTable{:,'Xnb'},app.KTMTable{:,'SOD'})-app.KTMTable{:,'x_m_'};
DX=DX.*DX;
DY=interp1(RSOD,app.RNETTable{:,'Ynb'},app.KTMTable{:,'SOD'})-app.KTMTable{:,'y_m_'};
DY=DY.^2;
%return the sum of the squares of the differences
SSD=sum(DX)+sum(DY);
end
end
% From a push button function callback, I use fminbnd to determine the time offset that results in the
% minimum sum of the squares of the differences
dTime=fminbnd(@SSDelta,-20.0,20.0);
% I get the error
Undefined function 'SSDelta' for input arguments of type 'double'.
Error in fminbnd (line 238)
fx = funfcn(x,varargin{:});
% I am open to an alternate approach, although I have a number of these, so I would like to use appdesigner

Respuesta aceptada

Umar
Umar el 26 de Jun. de 2024

Hi Stephen,

It appears that the function `SSDelta` is not recognized within the context of the `fminbnd` optimization call. This issue arises because the `SSDelta` function is defined as a method within the class or app that you are working with (assuming it is an App Designer app given your reference to `appdesigner`).

To address this problem, you need to ensure that the `SSDelta` function is accessible within the scope of the optimization call. One way to achieve this is by explicitly referencing the method within your App Designer app.

You can modify your code as follows:

1. Ensure that the `SSDelta` method is defined within your App Designer class or app script. 2. Modify the optimization call to directly reference the method within the app instance. You can do this by calling `app.SSDelta` instead of just `SSDelta`.

Here's an updated snippet of your code with these modifications:

 % Inside your App Designer class or script 

methods (Access = public)

function SSD = SSDelta(app,dTime)

 % Your existing SSDelta function implementation 
end 
end  

% Update the optimization call to use 'app.SSDelta'

dTime = fminbnd(@(x) app.SSDelta(x), -20.0, 20.0);

By making these adjustments, you should be able to resolve the "Undefined function 'SSDelta' for input arguments of type 'double'" error and successfully run your optimization routine to determine the time offset that minimizes the sum of squares of differences between your data sources.

Hope this will help resolve your issue.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by