-
Notifications
You must be signed in to change notification settings - Fork 2
/
editStruct.m
61 lines (56 loc) · 1.67 KB
/
editStruct.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
%% VolumeCut: Cut images along custom surfaces
% Copyright (C) 2017-2019 Luca Della Santina
%
% This file is part of VolumeCut
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% This software is released under the terms of the GPL v3 software license
%
function structOut = editStruct(structIn, title, prompt)
%% Edit structure using a dynamically generated GUII
% Enter the Structure first. optionally enter title, and then prompts
% Data type (num or string) should be preserved
fnames = fieldnames(structIn);
if nargin < 3
prompt = fnames;
end
if nargin < 2
title = 'Settings';
end
nLines = 1;
for i = 1:length(fnames)
var = structIn.(fnames{i});
if ischar(var)
notstr(i) = 0;
gVars{i} = var;
else
gVars{i} = num2str(var);
notstr(i) = 1;
end
end
gVars = inputdlg(prompt,title,nLines,gVars);
if numel(gVars) == 0
structOut = [];
return
else
pause(0.1);
structOut = struct;
for i = 1:length(fnames)
if notstr(i)
structOut.(fnames{i}) = str2double(gVars{i});
else
structOut.(fnames{i}) = gVars{i};
end
end
end