|
1 | 1 | function parsStruct = inferParameters(expdef) |
2 | | -%EXP.INFERPARAMETERS Infers the parameters required for experiment |
3 | | -% Detailed explanation goes here |
| 2 | +%EXP.INFERPARAMETERS Infers the parameters defined in an exp def |
| 3 | +% |
| 4 | +% Inputs: |
| 5 | +% 'expdef': the "experiment definition" .m file from which the parameters |
| 6 | +% are inferred. This argument can be set as a string or function handle |
| 7 | +% |
| 8 | +% Outputs: |
| 9 | +% 'parsStruct': the inferred parameters, returned as a MATLAB struct |
| 10 | +% |
| 11 | +% Example: |
| 12 | +% parsStruct = exp.inferParameters([fileparts(which('addRigboxPaths'))... |
| 13 | +% '\signals\doc\examples\expdefs\...']); |
| 14 | +% |
| 15 | +% fh = @... |
| 16 | +% parsStruct = exp.inferParameters(fh) |
| 17 | +% |
| 18 | +% See also: |
| 19 | +% |
| 20 | +% todo: update example |
4 | 21 |
|
5 | | -% create some signals just to pass to the definition function and track |
6 | | -% which parameter names are used |
7 | | - |
8 | | -if ischar(expdef) && file.exists(expdef) |
9 | | - expdeffun = fileFunction(expdef); |
10 | | -else |
11 | | - expdeffun = expdef; |
12 | | - expdef = which(func2str(expdef)); |
| 22 | +try |
| 23 | + if ischar(expdef) && file.exists(expdef) % if 'expdef' is a string |
| 24 | + expdeffun = fileFunction(expdef); |
| 25 | + else % if 'expdef' is a function handle |
| 26 | + expdeffun = expdef; |
| 27 | + expdef = which(func2str(expdef)); |
| 28 | + end |
| 29 | +catch ex |
| 30 | + error(['Input argument must be a string of the full filename,'... |
| 31 | + 'or a function handle']); |
13 | 32 | end |
14 | 33 |
|
| 34 | +% create some signals just to pass to the exp def and track which parameter |
| 35 | +% names are used |
15 | 36 | e = sig.void; |
16 | 37 | pars = sig.void(true); |
17 | 38 | audio.Devices = @dummyDev; |
18 | 39 |
|
| 40 | +% try to call the exp def file get the parameters defined in the file |
19 | 41 | try |
20 | 42 | expdeffun(e.t, e.events, pars, e.visual, e.inputs, e.outputs, audio); |
21 | | - |
22 | | - % paramNames will be the strings corresponding to the fields of pars |
23 | | - % that the user tried to reference in her expdeffun. |
24 | 43 | parsStruct = pars.Subscripts; |
25 | 44 |
|
26 | 45 | % Check for reserved fieldnames |
|
0 commit comments