-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratesamples.m
More file actions
63 lines (53 loc) · 1.93 KB
/
generatesamples.m
File metadata and controls
63 lines (53 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [ ] = generatesamples( dim, lowerlimit, upperlimit, step, varargin )
%GENERATESAMPLES Get samples from mathematica
% Optional parameters accepted:
% verbose - true/false depending if you want to see detailed output
% exponents - mathematica-formatted list of exponents for the distribution
% e.g. {1,2,3,4,5}
% seed - an integer seed
% Set defaults
verbose = false;
exponents = false;
if ~isempty(varargin)
if (rem(length(varargin),2)==1)
error('Optional parameters should always go by pairs');
else
for i=1:2:(length(varargin)-1)
if ~ischar (varargin{i}),
error (['Unknown type of optional parameter name (parameter' ...
' names must be strings).']);
end
% change the value of parameter
switch lower (varargin{i})
case 'verbose'
verbose = strcmpi(varargin{i+1}, 'true');
case 'exponents'
exponents = true;
expcode = varargin{i+1};
case 'seed'
seed_given = true;
seed = varargin{i+1};
otherwise
error(['Unknown argument: ''' varargin{i} '''']);
end;
end;
end;
end;
% We'll need the path to this file later
thisfolder = strrep(mfilename('fullpath'), mfilename(), '');
% Generate the samples from mathematica
params = [int2str(dim) ' ' int2str(lowerlimit) ' ' ...
int2str(upperlimit) ' ' int2str(step)];
if exponents
params = [params ' "' expcode '" ' num2str(seed)];
end
% On windows, need to call the kernel explicitly.
% On Linux, mathematicasamples.w uses a shebang to run the kernel
if ispc
cmd = ['"C:\Program Files\Wolfram Research\Mathematica\10.1\math" -script "' ...
thisfolder 'mathematicasamples.w" ' params];
else
cmd = [thisfolder 'mathematicasamples.w ' params];
end
system(cmd);
end