Zapit Optostim
  • Zapit Optostim: Introduction
    • Feature List
    • FAQ
  • Installation and Setup
    • Hardware setup
    • Software setup
    • Configuring Zapit
      • General settings
      • NI DAQ settings
      • Experiment settings
      • Scanner & Camera settings
      • Laser Power Calibration
      • Blanking settings
    • Staying up to date
  • Using the GUI
    • Introduction: Using the GUI
    • Scanner Calibration
    • Sample Calibration
    • StimConfig Editor
    • Generating stimulus patterns at the CLI
    • Advanced Usage
  • Running Experiments
    • Introduction: Running Experiments
    • MATLAB
      • Basic API Usage in MATLAB
      • Running an Experiment in MATLAB
    • Python
      • Connecting Python to Zapit
      • Basic Zapit API Use in Python
    • Remote Control and Other Programming Languages
  • Developer Notes
    • Project Structure
    • Conventions
    • Hints and Tips
Powered by GitBook
On this page
  1. Running Experiments
  2. MATLAB

Running an Experiment in MATLAB

Using the Zapit API in MATLAB

The following example function presents 20 random stimuli using software timing.

function myStimPresenter
    
    % Get the API object from the base workspace
    hZP = zapit.utils.getObject;
    if isempty(hZP)
        return
    end

    if hZP.isReadyToStim == false
        fprintf('Zapit is not ready to stimulate.\n')
        return
    end

    % Present 20 random stimuli without waiting for a hardware trigger
    for ii = 1:20
        hZP.sendSamples('hardwareTriggered',false) % Starts right away
        pause(1) % Wait approx 1s 
        hZP.stopOptoStim
        pause(0.3) % Because of https://github.com/Zapit-Optostim/zapit/issues/102
    end

end

The following function presents 20 random stimuli using an external hardware trigger:

function myStimPresenter
    
    % Get the API object from the base workspace
    hZP = zapit.utils.getObject;
    if isempty(hZP)
        return
    end

    if hZP.isReadyToStim == false
        fprintf('Zapit is not ready to stimulate.\n')
        return
    end

    % Present 20 random 1 second stimuli without waiting for a hardware trigger
    for ii = 1:20
        hZP.sendSamples('hardwareTriggered',true,'stimDurationSeconds',1)
    end
end

PreviousBasic API Usage in MATLABNextPython

Last updated 5 months ago

Note the 0.3 seconds pause after the stopOptoStim in the first example. the laser power ramp-down time which is triggered by stopOptoStim. The system will not respond to an external trigger during this period in hardware triggered mode. The pause is almost certainly only needed during demo code. In reality it is unlikely one trial will follow the previous one with a latency of <300 ms. Add a timeout to your behavior code to avoid this should it be a possibility.

This is to take into account