-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct2ws.m
72 lines (67 loc) · 1.67 KB
/
struct2ws.m
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
64
65
66
67
68
69
70
71
72
function struct2ws(s,varargin)
% struct2ws(s,varargin)
%
% Description : This function returns fields of scalar structure s in the
% current workspace
% __________________________________
% Inputs :
% s (scalar structure array) : a structure that you want to throw in
% your current workspace.
% re (string optional) : a regular expression. Only fields
% matching re will be returned
% Outputs :
% No output : variables are thrown directly in the caller workspace.
%
% Examples :
%
% Example 1:
% >> who
%
% Your variables are:
%
% params
%
% >>struct2ws(params)
% >> who
%
% Your variables are:
%
% blanc grille ratio_ecran unitX
% c_map gris rect unitY
% centre magni_jitt taille window
% dim_grille noir taille_cr zoomzoom
% epais_cr params taille_items
%
% Example 2:
% >> struct2ws(params,'unit')
% >> who
%
% Your variables are:
%
% params unitX unitY
%
%
% _____________________________________
% See also : ws2struct ; regexp
%
% Maximilien Chaumon v1.0 02/2007
if length(s) > 1
error('Structure should be scalar.');
end
if not(isempty(varargin))
re = varargin{1};
else
re = '.*';
end
vars = fieldnames(s);
vmatch = regexp(vars,re);
varsmatch = [];
for i = 1:length(vmatch)
if isempty(vmatch{i})
continue
end
varsmatch(end+1) = i;
end
for i = varsmatch
assignin('caller',vars{i},s.(vars{i}));
end