Change the matlab file name to include the date in the filename

This commit is contained in:
Thomas Dehaeze 2019-05-13 22:35:37 +02:00
parent 7ae17e7a60
commit 299c7336df

View File

@ -19,35 +19,32 @@ if tg.Connected == "Yes"
if tg.Status == "stopped" if tg.Status == "stopped"
disp('Load the Application'); disp('Load the Application');
tg.load('measure_channels'); tg.load('measure_channels');
%% Get the current date for the filename
% Get the current date and time
date_str = erase(cellstr(num2str(clock')), ' ');
% Don't take the seconds and add some "_"
date_str = strjoin(date_str(1:5), '_');
%% Run the application %% Run the application
disp('Starting the Application'); disp('Starting the Application');
tg.start; tg.start;
pause(Tsim); pause(Tsim);
tg.stop; tg.stop;
%% Get the data from the speedgoat
f = SimulinkRealTime.openFTP(tg);
cd(f, 'data/measure_channels/');
mget(f, 'data_001.dat', 'data');
close(f);
% Convert the data to a Matlab object
data = SimulinkRealTime.utils.getFileScopeData('data/data_001.dat').data;
%% Save the new data into one mat file
save(['mat/data_', date_str, '.mat'], 'data');
else
error("The target computer is running");
end end
else else
error("The target computer is not connected"); error("The target computer is not connected");
end end
%%
f = SimulinkRealTime.openFTP(tg);
cd(f, 'data/measure_channels/');
mget(f, 'data_001.dat', 'data');
close(f);
data = SimulinkRealTime.utils.getFileScopeData('data/data_001.dat').data;
%%
n = 52;
while isfile(['mat/data_', num2str(n, '%03d'), '.mat'])
disp('File exists.');
if input(['Are you sure you want to override the file ', 'mat/data_', ...
num2str(n, '%03d'), '.mat', ' ? [Y/n]']) == 'Y'
break;
end
n = input('What should be the measurement number?');
end
save(['mat/data_', num2str(n, '%03d'), '.mat'], 'data');