0001 function [p,data]=nt_dataview(data,p)
0002
0003
0004
0005
0006
0007
0008
0009 VERBOSE=1;
0010
0011 if nargin < 1;
0012
0013 [p,data]=nt_dataview('/');
0014 return
0015 end
0016
0017 if nargin < 2; p=[]; end
0018 if isempty(data); return; end
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 if ~isfield(p,'data_name')
0049 if isa(data,'char');
0050 p.data_name=data;
0051 elseif isa(data,'struct');
0052 p.data_name='structure';
0053 elseif isnumeric(data)
0054 p.data_name='matrix';
0055 else
0056 error('argument should be string, struct, or numeric');
0057 end
0058 end
0059
0060
0061
0062 if isnumeric(data)
0063
0064 if ~isa(data, 'double')
0065 warning('converting data to double');
0066 data=double(data);
0067 end
0068
0069 if ~isempty(p) && isfield(p, 'matrix_modify');
0070 eval([p.matrix_modify,';']);
0071 end
0072
0073 nt_whoss;
0074 if VERBOSE; disp('matrix'); end
0075 nDims=ndims(data);
0076 if nDims==2 && (size(data,1)==1 || size(data,2)==1); nDims=1; end
0077 if nDims>4; nDims=4; end
0078
0079
0080 posFig=[0 100, 1000, 400];
0081 posButtonReturn=[50, 20, 100, 25];
0082 posButtonAssign=[200, 20, 300, 25];
0083 posEdit=[100 70 800 30];
0084
0085
0086 dialogH=figure('Visible','on', 'WindowStyle','normal', 'Name',p.data_name, 'NumberTitle','off',...
0087 'Pointer','arrow', 'Position',posFig,'color', [1 1 1], 'KeyPressFcn',@doFigureKeyPress,...
0088 'IntegerHandle','off', 'CloseRequestFcn' ,@doDelete);
0089 editH=[]; buttonReturnH=[];
0090 set(gcf,'userdata',p);
0091 done=0;
0092 while ~done
0093
0094
0095 plot_params.bottom=0.35; plot_params.height=0.5;
0096
0097
0098 nt_statmatrix(data,plot_params);
0099
0100 if isfield(p,'return') && p.return; break; end
0101
0102
0103 whichButton=[];
0104 returnPressed=[];
0105 escapePressed=[];
0106 otherKeyPressed=[];
0107
0108
0109 buttonReturnH=uicontrol('style', 'pushbutton', 'string', 'Return','position', posButtonReturn,...
0110 'KeyPressFcn',@doControlKeyPress, 'Callback',@doButtonPress, 'HorizontalAlignment','center', 'parent', dialogH,...
0111 'fontSize', 14);
0112
0113
0114 buttonAssignH=uicontrol('style', 'pushbutton', 'string', 'Assign to p,data in workspace','position', posButtonAssign,...
0115 'KeyPressFcn',@doControlKeyPress, 'Callback',@doButtonPress, 'HorizontalAlignment','center', 'parent', dialogH,...
0116 'fontSize', 14);
0117
0118 editString=['data=data( 1 : ',num2str(size(data,1))];
0119 for iDim=2:nDims
0120 editString=[editString,', 1 : ',num2str(size(data,iDim))];
0121 end
0122 editString=[editString,' );'];
0123 editH=uicontrol('Style','edit','String',editString,'position', posEdit, 'parent', dialogH,...
0124 'callback', @editCallback, 'foregroundcolor',[1 1 1]*0 );
0125
0126 if ~ ishghandle(dialogH); return; end
0127 uiwait(dialogH);
0128 if ~ ishghandle(dialogH); return; end
0129
0130
0131 if returnPressed
0132 done=1;
0133 elseif escapePressed
0134 done=1;
0135 elseif otherKeyPressed
0136 ;
0137 else
0138 h=get(dialogH,'CurrentObject');
0139
0140 if find(h==editH)
0141 s=get(editH(1),'string');
0142 try
0143 th=annotation('textbox', [.5 .04 .1 .1], 'string', 'evaluating...', 'fontsize', 14, 'edgecolor', [1 1 1]);
0144 drawnow
0145 if ~isempty(p) && isfield(p, 'matrix_modify');
0146 p.matrix_modify=[p.matrix_modify, s];
0147 else
0148 p.matrix_modify=s;
0149 end
0150 eval(s);
0151 set(th,'string','');
0152 clf
0153 catch
0154 beep;
0155 warning(['incorrect indexing string: >',s,'<']);
0156 end
0157 elseif h==buttonReturnH
0158 done=1;
0159 elseif h==buttonAssignH
0160 assignin('base','p',p);
0161 assignin('base','data',data);
0162 done=1;
0163 else
0164 disp(num2str(h));
0165 error('unexpected handle')
0166 end
0167 end
0168
0169 end
0170
0171 set(gcf,'userdata',p);
0172 if ~isempty(editH); delete(editH); end
0173 if ~isempty(buttonReturnH); delete(buttonReturnH); end
0174 if ishghandle(dialogH); delete(dialogH); end
0175
0176
0177
0178
0179 if nargout==0; clear data p; end
0180
0181 if VERBOSE; disp('returning from nt_dataview...'); end
0182
0183
0184
0185
0186
0187 elseif isa(data, 'struct')
0188
0189 if VERBOSE; disp('struct'); end
0190 if isempty(struct); error('''struct'' is empty!'); end
0191 field_names=fieldnames(data);
0192 if isempty(field_names); error('structure is empty!'); end
0193 field_sizes=zeros(numel(field_names),1);
0194 for k=1:numel(field_names);
0195 field=getfield(data,field_names{k});
0196 field_sizes(k)=round(prod(size(field))/1024);
0197 end
0198 clear field;
0199 a=repmat(' (', numel(field_names),1);
0200 b=cellstr(num2str(field_sizes, '%9d'));
0201 b=char(b);
0202 c=[repmat(' Mb)', numel(field_names),1)];
0203 i=listdlg('liststring',cellstr([char(field_names),a,b,c]),...
0204 'name', 'Select field in struct:', ...
0205 'listsize', [600 300], ...
0206 'OKstring','Select',...
0207 'PromptString',p.data_name);
0208
0209
0210 if i
0211 data=getfield(data,field_names{i});
0212 [p,data]=nt_dataview(data,p);
0213 if nargout==0; data=[]; end
0214 return
0215 end
0216
0217
0218
0219 elseif isa(data, 'char') && ...
0220 ( exist(data,'file')==2 || ...
0221 (numel(data)>3 && all(data(end-2:end)=='.ds')))
0222
0223
0224 fname=data;
0225 if VERBOSE; disp('file'); end
0226
0227 if 0
0228
0229 if numel(fname)>4 & fname(end-3:end)=='.mat'
0230 if VERBOSE; disp('mat file'); end
0231 S=whos('-file',fname);
0232 var_names=char(S.name);
0233 var_sizes=round([S.bytes]/1024)';
0234 a=repmat(' (', size(var_names,1),1);
0235 b=cellstr(num2str(var_sizes, '%9d'));
0236 b=char(b);
0237 c=[repmat(' Mb)', size(var_names,1),1)];
0238 i=listdlg('liststring',cellstr([var_names,a,b,c]),...
0239 'name', 'Select variable in file:', ...
0240 'listsize', [600 300], ...
0241 'OKstring','Select',...
0242 'PromptString',p.data_name);
0243 if i
0244 X=load(fname,var_names(i,:));
0245 [p,data]=nt_dataview(X,p);
0246 end
0247 if nargout==0; data=[]; end
0248 return
0249 end
0250 end
0251
0252
0253 [p,data]=nt_read_data(fname);
0254 [p,data]=nt_dataview(data,p);
0255 return
0256
0257
0258 elseif isa(data, 'char') && exist(data, 'dir')==7
0259
0260 if VERBOSE; disp('directory'); end
0261
0262 d=dir(data);
0263 if numel(d)==0
0264 error(['directory >',data,'< not found']);
0265 end
0266 fnames=char(d.name);
0267 idx=find(fnames(:,1)~='.');
0268 d=d(idx);
0269 fnames=fnames(idx,:);
0270
0271
0272 didx=find([d.isdir]);
0273 fidx=find(~[d.isdir]);
0274 fnames=fnames([didx, fidx],:);
0275
0276
0277 nfiles=zeros(numel(didx),1);
0278 for k=1:numel(didx)
0279 dd=dir([data,'/',d(didx(k)).name]);
0280 fns=char(dd.name);
0281 idx=find(fns(:,1)~='.');
0282 nfiles(k)=numel(idx);
0283 end
0284
0285
0286 mbytes=[d(fidx).bytes]'/1024;
0287
0288
0289 a=repmat(' (', numel(d),1);
0290 if numel(didx)>0
0291 b=cellstr(num2str(nfiles, '%9d'));
0292 else
0293 b=[];
0294 end
0295 if numel(fidx)>0
0296 b=[b;cellstr(num2str(mbytes,'%0.1f'))];
0297 end
0298 b=char(b);
0299 c=[repmat(' files)', numel(didx),1); repmat(' Mb) ', numel(fidx),1)];
0300
0301
0302
0303 i=listdlg('liststring',cellstr([fnames,a,b,c]),...
0304 'name', 'Select file:', ...
0305 'listsize', [300 300], ...
0306 'OKstring','Select',...
0307 'PromptString',p.data_name);
0308
0309
0310 if i
0311 data=strcat(data,'/',fnames(i,:));
0312 [p,data]=nt_dataview(data,p);
0313 end
0314 return
0315 else
0316 disp([p.data_name,' not found']);
0317 if nargout==0; data=[]; end
0318 return
0319 end
0320
0321
0322
0323 if nargout==0;
0324 disp('hereiam');
0325 clear data p
0326 end
0327
0328
0329
0330
0331
0332 function doFigureKeyPress(obj, evd)
0333 switch(evd.Key)
0334 case {'return','space'}
0335 returnPressed = true;
0336 case 'escape'
0337 escapePressed=true;
0338 otherwise
0339 otherKeyPressed=true;
0340 end
0341 uiresume(gcbf)
0342 end
0343
0344 function doDelete(varargin)
0345 delete(dialogH);
0346 end
0347
0348 function editCallback(obj,evd);
0349
0350 uiresume(gcbf);
0351 end
0352
0353 function doButtonPress(obj,evd);
0354 whichButton=obj;
0355 uiresume(gcbf);
0356 end
0357 function doButtonPress2(obj,evd);
0358 whichButton=obj;
0359 p=get(gcf,'userdata');
0360 evalin('caller',p.recreate);
0361 end
0362
0363
0364
0365 end