init¶
init connects your plugin to AnyWave and returns all the settings AnyWave defined for it
(the current data file, the sidecar files, the folders, the options of the command line...).
It must be the first call to anywave().
function main(varargin)
args = anywave('init', varargin);
Warning
Always pass varargin, exactly as it is. AnyWave puts in it the information needed to connect to your plugin.
What is in args¶
args is a struct, one field per setting. The most useful ones:
| field | content |
|---|---|
data_path |
full path of the data file |
data_dir, data_file, data_file_no_ext |
folder, file name, file name without extension |
file_duration, total_duration |
duration of the data in seconds |
samples, max_sr |
number of samples per channel, highest sampling rate of the file (Hz) |
marker_file |
path of the marker file (.mrk) of the data file |
montage_file |
path of the montage file (.mtg) |
bad_file |
path of the bad channels file (.bad) |
flt_file, disp_file, sel_file |
paths of the filters, display and selection files |
ica_file |
path of the ICA file currently in use (empty if none) |
bad_labels |
labels of the channels marked as bad (only with init and debug_connect) |
iso_date, recording_date, recording_time |
date and time of the acquisition |
first_name, last_name, birth_date |
subject information (n/a when unknown) |
bids |
true when the file belongs to a BIDS dataset |
work_dir, home_dir, log_dir, plugins_dir |
AnyWave folders |
The list depends on the context and on the version of AnyWave. To see exactly what you get, print it:
function main(varargin)
args = anywave('init', varargin);
disp(fieldnames(args));
anywave('send_message', ['Data file: ' args.data_path]);
end
Typical uses¶
Save a result next to the data file:
function main(varargin)
args = anywave('init', varargin);
result_file = fullfile(args.data_dir, [args.data_file_no_ext '_result.mat']);
save(result_file, 'args');
end
Cut the file in blocks of 30 seconds:
function main(varargin)
args = anywave('init', varargin);
block = 30; % seconds
nblocks = ceil(args.file_duration / block);
for b = 1:nblocks
cfg = [];
cfg.start = (b - 1) * block;
cfg.duration = block;
out = anywave('get_data', cfg);
% ... process out.data
end
end
Note
args.bad_labels lists the channels marked as bad. It is empty ([]) when there is none.
get_data already leaves the bad channels out unless you ask for them, see get_data.
When the plugin runs from the command line¶
If the plugin is launched with anywave --run MyPlugin ..., args also contains the options of the command line
(for instance args.input_file), see Write a MATLAB plugin and
BIDS Pipeline compatibility.
In a debug session¶
init works after debug_connect: call anywave('init', {}), or simply run your main function
without arguments.
anywave('debug_connect', 59000);
main(); % runs your plugin on the file open in AnyWave