Skip to content

Run Experiment For Set Duration

This examples shows how to use MATLAB to control the Synapse mode and monitor recording status
This uses the 'ExperimentSetTime' example experiment, but it could run with any experiment

Download M File

Download Experiment File

Housekeeping

Clear workspace and close existing figures. Add SDK directories to MATLAB

close all; clear all; clc;
[APIEXAMPLESPATH,name,ext] = fileparts(cd); % \TDTMatlabSDK\Examples
[SDKPATH,name,ext] = fileparts(APIEXAMPLESPATH); % \TDTMatlabSDK
addpath(genpath(SDKPATH));

Setup

Choose which experiment to run and the duration. It could be anything. This example uses a simple experiment with just a Tick store. To see full list of available experiments use syn.getKnownExperiments()

EXPERIMENT = 'ExperimentSetTime';
TOTAL_TIME = 30;

% Connect to Synapse
syn = SynapseAPI();

% Set your experiment
syn.setCurrentExperiment(EXPERIMENT);

Runtime

Set the system to 'Preview' mode

syn.setModeStr('Preview');

% Wait five seconds to give 'getSystemStatus' time to update internally
pause(5);

Main Loop

currTime = 0; prevTime = 0;
% Poll the system status until it reaches the desired state
while currTime < TOTAL_TIME
    % Add any additional API controls here
    currTime = syn.getSystemStatus.iRecordSecs;
    if prevTime ~= currTime
        fprintf('Current elapsed time: %ds\n', currTime);
    end
    prevTime = currTime;
end
Current elapsed time: 1s
Current elapsed time: 2s
Current elapsed time: 3s
Current elapsed time: 4s
Current elapsed time: 5s
Current elapsed time: 6s
Current elapsed time: 7s
Current elapsed time: 8s
Current elapsed time: 9s
Current elapsed time: 10s
Current elapsed time: 11s
Current elapsed time: 12s
Current elapsed time: 13s
Current elapsed time: 14s
Current elapsed time: 15s
Current elapsed time: 16s
Current elapsed time: 17s
Current elapsed time: 18s
Current elapsed time: 19s
Current elapsed time: 20s
Current elapsed time: 21s
Current elapsed time: 22s
Current elapsed time: 23s
Current elapsed time: 24s
Current elapsed time: 25s
Current elapsed time: 26s
Current elapsed time: 27s
Current elapsed time: 28s
Current elapsed time: 29s
Current elapsed time: 30s

Our desired elapsed time has passed, switch to Idle mode

syn.setModeStr('Idle');
disp('done');
done

Runtime Output