|
| 1 | +% This function allow calling vis_stream with simply a string of character |
| 2 | +% so it can be used to set parameters after being compiled. Make sure there |
| 3 | +% are no spaces for parameter values or the string will not be parsed |
| 4 | +% properly. |
| 5 | +% |
| 6 | +% Example: vis_stream_comp('samplingrate 200 refreshrate 5 position [100,100,500,500]'); |
| 7 | + |
| 8 | +function vis_stream_comp(varargin) |
| 9 | + |
| 10 | +% parse parameters |
| 11 | +if nargin == 1 && ischar(varargin{1}) |
| 12 | + strparams = varargin{1}; |
| 13 | + opt = textscan(strparams, '%s'); |
| 14 | + opt = opt{1}; |
| 15 | + for iOpt = 1:length(opt) |
| 16 | + if opt{iOpt}(1) == '-' |
| 17 | + opt{iOpt} = opt{iOpt}(2:end); |
| 18 | + end |
| 19 | + indminus = find(opt{iOpt} == '-'); |
| 20 | + for iIndminus = 1:length(indminus) |
| 21 | + if opt{iOpt}(indminus(iIndminus)-1) == ' ' |
| 22 | + opt{iOpt}(indminus(iIndminus)) = '_'; |
| 23 | + end |
| 24 | + end |
| 25 | + end |
| 26 | + opt = struct(opt{:}); |
| 27 | +elseif nargin == 1 && isstruct(varargin{1}) |
| 28 | + opt = varargin{1}; |
| 29 | +elseif nargin > 1 |
| 30 | + opt = struct(varargin{:}); |
| 31 | +else |
| 32 | + opt = struct([]); |
| 33 | +end |
| 34 | + |
| 35 | +numFields = { 'bufferrange' 'timerange' 'channelrange' 'samplingrate' 'refreshrate' 'freqfilter' 'position' 'reref' 'standardize' 'zeromean' }; |
| 36 | + |
| 37 | +for iField = 1:length(numFields) |
| 38 | + if isfield(opt, numFields{iField}) && ischar(opt.(numFields{iField})) |
| 39 | + opt.(numFields{iField}) = str2num(opt.(numFields{iField})); % will convert booleans as well |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +fieldNames = fieldnames(opt); |
| 44 | +fieldValues = struct2cell(opt); |
| 45 | +fieldNames(:,2) = fieldValues; |
| 46 | +fieldNames = fieldNames'; |
| 47 | +fieldNames = fieldNames(:)'; |
| 48 | + |
| 49 | +vis_stream(fieldNames{:}); |
0 commit comments