Browse code

class def parsing added strtrunc.m

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@94 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on17/12/2008 18:42:12
Showing4 changed files
... ...
@@ -28,8 +28,6 @@ end
28 28
 
29 29
         display('done.');
30 30
         
31
-        
32
-        
33 31
         params = struct;
34 32
         params.nClasses = 2;
35 33
 
... ...
@@ -48,15 +46,18 @@ end
48 46
         calculateParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
49 47
         calculateParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;
50 48
 
51
-        calculateParams.voxelList = parseVoxelList(paramModel);
49
+        calculateParams.voxelList       = parseVoxelList(paramModel);
52 50
 
53 51
         calculateParams.svmargs         = get(paramModel.txtSVMopts,'String');
54 52
         calculateParams.sessionList     = 1:3;
55 53
 
56
-%         parseClassDef(paramModel)
57
-        calculateParams.classList       = {'<','>'};
58
-        calculateParams.labelMap        = LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4});
59
-        calculateParams.eventList       = [9,11,13; 10,12,14];
54
+        classStruct = parseClassDef(paramModel);
55
+        assignin('base','classStruct',classStruct);
56
+        
57
+        calculateParams.classList       = classStruct.label; %{'<','>'};
58
+        calculateParams.labelMap        = LabelMap(classStruct.label , classStruct.value); % LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4});
59
+        calculateParams.eventList       = classStruct.event; %[9,11,13; 10,12,14];
60
+        
60 61
         
61 62
         assignin('base','calculateParams',calculateParams);
62 63
         
63 64
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+function outstruct = parseClassDef(model)
2
+outstruct = struct;
3
+txt = get(model.txtClassDef,'String');
4
+
5
+% txt =txt(find(all(isspace(txt(i,:))) ???
6
+
7
+nClasses = size(txt,1); % clear empty lines!
8
+
9
+outstruct.event = [];
10
+
11
+for i = 1:nClasses
12
+    line = txt(i,:);
13
+    delim = strfind(line,','); %first and last are real delimiter
14
+
15
+    outstruct.label{i} = strtrunc(line(1:delim(1)-1));
16
+    outstruct.event    = [outstruct.event ; eval(strtrunc(line(delim(1)+1:delim(length(delim))-1)))];
17
+    outstruct.value{i} = strtrunc(line(delim(length(delim))+1:length(line)));
18
+end
19
+
20
+end
... ...
@@ -78,6 +78,7 @@ function spm_SVMCrossVal
78 78
     set(model.txtClassDef,'HorizontalAlignment','left');
79 79
     set(model.txtClassDef,'Max',20);
80 80
     set(model.txtClassDef,'Min',0);
81
+    set(model.txtClassDef, 'FontName', 'FixedWidth')
81 82
     
82 83
     %Voxel
83 84
     nVoxelRows = 8;
... ...
@@ -88,10 +89,11 @@ function spm_SVMCrossVal
88 89
 
89 90
     lVoxelDef = createLabel(pVOXEL, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<ROI Name>,<ROI Modifier>;');
90 91
     model.txtVoxelDef = createTextField(pVOXEL,[firstColumn secondRow 0.98*frameWidth 6*controlElementHeight],...
91
-        sprintf('M1 l,\t[ 0, 0, 0];\nM1 l,\t[ 1, 0, 0];\nM1 l,\t[ 0, 1, 0];\nM1 l,\t[ 1, 0, 1];\n'));
92
+        sprintf('M1 l,\t[ 0, 0, 0];\nM1 l,\t[ 1, 0, 0];\nM1 l,\t[ 0, 1, 0];\nM1 l,\t[ 0, 0, 1];\n'));
92 93
     set(model.txtVoxelDef,'HorizontalAlignment','left');
93 94
     set(model.txtVoxelDef,'Max',20);
94 95
     set(model.txtVoxelDef,'Min',0);
96
+    set(model.txtVoxelDef, 'FontName', 'FixedWidth')
95 97
                 
96 98
     % SVM
97 99
     firstColumn  =  5.00;
98 100
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+% function s = strtrunc(str)
2
+% s=str;
3
+% c=1
4
+% while isspace(s(c)) 
5
+%     s = s(2:length(s))
6
+% end
7
+% while isspace(s(length(s)))
8
+%     s = s(1:length(s)-1);
9
+% end
10
+% end
11
+
12
+function s = strtrunc(str)
13
+if isspace(str(1))
14
+    s = strtrunc(str(2:length(str)));
15
+elseif isspace(str(length(str)))
16
+    s = strtrunc(str(1:length(str)-1));
17
+else
18
+    s = str;
19
+end
20
+end
0 21
\ No newline at end of file