|
9 | 9 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
|
10 | 10 |
|
11 | 11 | % Vladimir Litvak
|
12 |
| -% $Id: checkmeeg.m 3978 2010-07-08 14:26:39Z vladimir $ |
| 12 | +% $Id: checkmeeg.m 4207 2011-02-22 10:48:36Z christophe $ |
13 | 13 |
|
14 | 14 | if nargin==1
|
15 | 15 | option = 'basic';
|
|
64 | 64 | end
|
65 | 65 |
|
66 | 66 | for k = 1:Ntrials
|
67 |
| - if isnumeric(meegstruct.trials(k).label) |
68 |
| - meegstruct.trials(k).label = num2str(meegstruct.trials(k).label); |
| 67 | + |
| 68 | + label = meegstruct.trials(k).label; |
| 69 | + |
| 70 | + if iscell(label) && numel(label) == 1 |
| 71 | + label = label{1}; |
69 | 72 | end
|
70 | 73 |
|
| 74 | + if isnumeric(label) |
| 75 | + label = num2str(label); |
| 76 | + end |
| 77 | + |
| 78 | + if isa(label, 'char') |
| 79 | + meegstruct.trials(k).label = label; |
| 80 | + else |
| 81 | + meegstruct.trials(k).label = 'Unknown'; |
| 82 | + disp('checkmeeg: some trial labels were not strings, changing back to ''Unknown'''); |
| 83 | + end |
| 84 | + |
71 | 85 | if length(meegstruct.trials(k).bad)>1 || ~ismember(meegstruct.trials(k).bad, [0, 1])
|
72 | 86 | disp(['checkmeeg: illegal value for bad flag in trial ' num2str(k) ', setting to zero.']);
|
73 | 87 | meegstruct.trials(k).bad = 0;
|
|
135 | 149 | else
|
136 | 150 | [meegstruct.channels(find(cellfun('isempty', {meegstruct.channels.bad}))).bad] = deal(0);
|
137 | 151 | end
|
| 152 | + |
| 153 | + for i = 1:Nchannels |
| 154 | + meegstruct.channels(i).bad = double(~~meegstruct.channels(i).bad); |
| 155 | + end |
| 156 | + |
138 | 157 | if ~isfield(meegstruct.channels, 'type')
|
139 | 158 | disp('checkmeeg: no channel type, assigning default');
|
140 | 159 | [meegstruct.channels.type] = deal('Other');
|
|
199 | 218 | end
|
200 | 219 |
|
201 | 220 | if isa(meegstruct.data.y, 'file_array')
|
| 221 | + % catching up (unlikely case) where filearray.fname is |
| 222 | + % different from data.fnamedat -> set data.fnamedat |
| 223 | + [junk, yfname, yext] = fileparts(meegstruct.data.y.fname); |
| 224 | + [junk, dfname, dext] = fileparts(meegstruct.data.fnamedat); |
| 225 | + if ~strcmp([yfname yext],[dfname dext]) |
| 226 | + meegstruct.data.fnamedat = [yfname yext]; |
| 227 | + end |
| 228 | + % save original file_array scale & offset, just in case |
| 229 | + sav_sc = meegstruct.data.y.scl_slope; |
| 230 | + sav_os = meegstruct.data.y.offset; |
202 | 231 | try
|
203 | 232 | % Try reading data, i.e. check if it's a "good" filearray
|
204 | 233 | meegstruct.data.y(1, 1, 1);
|
205 | 234 | catch
|
206 |
| - % save original file_array scale, just in case |
207 |
| - sav_sc = meegstruct.data.y.scl_slope; |
208 | 235 | meegstruct.data.y = [];
|
209 | 236 | end
|
210 | 237 | end
|
|
235 | 262 | error('Unknown transform type');
|
236 | 263 | end
|
237 | 264 | % and restore original file_array scale, if available (exist) & useful (~=[])
|
238 |
| - if exist('sav_sc','var') && ~isempty(sav_sc) |
| 265 | + if exist('sav_sc','var') && ~isempty(sav_sc) && ... |
| 266 | + size(meegstruct.data.y, 1) == length(sav_sc) |
239 | 267 | meegstruct.data.y.scl_slope = sav_sc;
|
240 | 268 | end
|
| 269 | + % and restore original file_array offset, if available (exist) & useful (~=0) |
| 270 | + if exist('sav_os','var') && sav_os |
| 271 | + meegstruct.data.y.offset = sav_os; |
| 272 | + end |
241 | 273 |
|
242 | 274 | end
|
243 | 275 |
|
|
0 commit comments