How can I avoid problems when using LOAD in the timer function in MATLAB (R14SP3)?

I am unable to load variables within my timer function (in my GUI) from a MAT file. These variables are generated by RSIM.

 Risposta accettata

You can solve the issue by defining these variables es empty. The following code is an extract of his GUI source code - the timer script:
function timer_function(varargin1, DIR_MEASGUI)
global t;
DIR_MEASGUI = 'd:\Hydraulik\';
DIR_PROG = 'd:\Hydraulik\prog\';
DIR_RAWDATA = 'd:\Hydraulik\data\raw\';
if(strcmp(varargin1, 'timer_start'))
% make timer that is adequate for checking the directory;D:\brake\data
t=timer('StartDelay', 2, 'Period', 3, 'ExecutionMode', 'fixedSpacing', 'BusyMode', 'drop');
%t=timer('StartDelay', 2, 'Period', 3, 'ExecutionMode', 'fixedSpacing','BusyMode','queue');
% set TimerFcn to 'timer_function_measurement()';
% cd(DIR_MEASGUI);
%load('D:\Hydraulik\prog\workspace.mat')
t.TimerFcn = {@my_timer_callback};
% start timer
start(t);
else
% stop timer and delete
stop(t);
disp('stop the measurement');
delete(t);
end
function my_timer_callback(obj, event)
% default data folder
disp('checking the directory....');
% scan directory for mat files and save into struct
TempDir = dir([ DIR_RAWDATA '\*.mat']);
if length(TempDir)>0
% if there is a file, execute 'measurement_description';
actual_dir = pwd;
%----------------------------------------------------------------
% without this part it doesn't work!
VX=[];
BLS=[];
ResetSpeedOnOff=[];
ResetSpeed=[];
Timevec=[];
TStart=[];
TFinal=[];
result=[];
Name=[];
VehicleSpeed_m_s=[];
tout=[];
%warning off
load('D:\Hydraulik\prog\workspace.mat')
TStart=Timevec(1);
TFinal=Timevec(end);
sim('only_stoppingdistance.mdl',[TStart TFinal]);
result=struct('MFDD',MFDD(end),'MeanDeceleration',MeanDeceleration_vref(end),'ResetSpeed',ResetSpeed,'ResetSpeedOnOff',ResetSpeedOnOff,'Stoppingdistance',Stoppingdistance(end),'Vo_measured',Vo_measured(end))
Name = ['StoppingDistance_Hydraulic_',datestr(now,'dd-mm-yyyy_HH-MM-SS')]
save (Name ,'Timevec','BrakeDemand','BrakeDemandActive','MFDD','MeanDeceleration_vref','MeasureActive_vref','ResetSpeed','ResetSpeedOnOff','Stoppingdistance','VX_Correvit','VehicleSpeed_km_h','Vo_measured','result');
%------------------------------------------------------
cd(actual_dir)
end
end
end

Più risposte (0)

Categorie

Scopri di più su Scope Variables and Generate Names in Centro assistenza e File Exchange

Prodotti

Release

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by