0001 function vb_plot_status(fname, plot_parm)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 npng = 0;
0018 NXmax = 4;
0019 NYmax = 4;
0020 Ymax = [];
0021 Ymin = [];
0022 plot_status = 1;
0023 plot_abs = 1;
0024 Pretrigger_ms = [ ];
0025 Posttrigger_ms = [ ];
0026
0027 if nargin == 1, plot_parm = []; end
0028
0029 if ~isfield(plot_parm,'mode'), plot_parm.mode = 1; end
0030 if ~isfield(plot_parm,'png'), plot_parm.png = []; end
0031
0032 if isfield(plot_parm,'NXmax'), NXmax = plot_parm.NXmax; end
0033
0034 if isfield(plot_parm,'NYmax'), NYmax = plot_parm.NYmax; end
0035
0036 if isfield(plot_parm,'Ymax'), Ymax = plot_parm.Ymax; end
0037 if isfield(plot_parm,'Ymin'), Ymin = plot_parm.Ymin; end
0038 if isfield(plot_parm,'status'), plot_status = plot_parm.status; end
0039 if isfield(plot_parm,'abs'), plot_abs = plot_parm.abs; end
0040 if isfield(plot_parm,'Pretrigger_ms'), Pretrigger_ms = plot_parm.Pretrigger_ms ; end
0041 if isfield(plot_parm,'Posttrigger_ms'), Posttrigger_ms = plot_parm.Posttrigger_ms; end
0042
0043 info = load(fname);
0044 parm = info.parm;
0045 ix_trial = info.ix_trial;
0046 trig = info.trig;
0047 status = info.status;
0048 status_out = info.status_out;
0049 status_val = info.status_val;
0050 cond_id = info.cond_id;
0051
0052
0053 fs = parm.fsamp;
0054 dt = 1000/fs;
0055 dT = 0;
0056
0057 [Nch, T] = size(status);
0058 Ncond = length(status_val);
0059
0060
0061 t = (0:(T-1))*dt;
0062
0063
0064 Ntrial = length(trig);
0065
0066 if isfield(plot_parm,'Ntrial') && ~isempty(plot_parm.Ntrial)
0067 Ntrial_id = plot_parm.Ntrial;
0068 else
0069 Ntrial_id = 1:Ntrial;
0070 end
0071
0072 if ~isempty(Pretrigger_ms)
0073
0074 Pretrigger = ceil(Pretrigger_ms *(fs/1000));
0075 Posttrigger = ceil(Posttrigger_ms*(fs/1000));
0076
0077 ix = (-Pretrigger:Posttrigger)';
0078 Tp = length(ix);
0079
0080
0081 ix_trial = repmat(ix,[1 Ntrial]) + repmat(trig,[Tp 1]);
0082 end
0083
0084 trg_on = trig*dt;
0085 trg_on = [trg_on ;trg_on];
0086
0087 trg_st = ix_trial(1,:)*dt;
0088 trg_end = ix_trial(end,:)*dt;
0089 trg_mid = mean(trg_end - trg_st);
0090 trg_st2 = trg_st - trg_mid/2;
0091
0092
0093 Nfig = ceil(Ntrial/NXmax);
0094
0095 switch plot_parm.mode
0096 case 1
0097 NX = 1;
0098 NXmax = ceil(Ntrial/NYmax);
0099 Nfig = NYmax;
0100 case 2
0101 NX = NXmax;
0102 case 3
0103 NX = 1;
0104 end
0105
0106 if Nfig < NYmax
0107 NY = Nfig;
0108 else
0109 NY = NYmax;
0110 end
0111
0112 switch plot_parm.mode
0113 case 1
0114
0115 plot_multi_cond;
0116 case 2
0117
0118 plot_each_trial;
0119 case 3
0120
0121 plot_multi_trial;
0122 end
0123
0124 end_figure(npng);
0125
0126
0127
0128
0129
0130 function plot_each_trial
0131 nfig = 1;
0132 npng = 0;
0133 figure;
0134
0135
0136 for n=Ntrial_id
0137 id = cond_id(n);
0138 if Nch == Ncond
0139 y = status(id,:);
0140 ys = status_out(id,:);
0141 else
0142 y = status;
0143 ys = status_out;
0144 end
0145
0146 if plot_abs == 1, y = abs(y); end
0147
0148 y = y/max(ys);
0149 ys = ys/max(ys);
0150
0151 ymax = max(y(ix_trial(:,n)));
0152
0153 y_trg = [0; ymax];
0154 y_status = [status_val(id); status_val(id)];
0155
0156
0157 [nfig ,npng] = new_figure(nfig,npng);
0158
0159 subplot(NY,NX,nfig);
0160
0161 plot(t,y)
0162 hold on
0163 plot(t,ys,'-b')
0164 plot(trg_on(:,n), y_trg ,'-r')
0165
0166 if plot_status == 1
0167
0168 plot([trg_st(n) ;trg_end(n)], y_status ,'-r')
0169 end
0170
0171 xlim([trg_st(n)-dT , trg_end(n)+dT])
0172 if ~isempty(Ymax)
0173 ylim([Ymin Ymax])
0174 end
0175
0176
0177 nfig=nfig+1;
0178 end
0179
0180 end
0181
0182
0183
0184 function plot_multi_trial
0185 nfig = 1;
0186 npng = 0;
0187 figure;
0188
0189
0190 for m=1:Nfig
0191
0192 [nfig ,npng] = new_figure(nfig,npng);
0193 subplot(NY,NX,nfig);
0194
0195 for n=1:Ncond
0196 id = cond_id(n);
0197 if Nch == Ncond
0198 y = status(id,:);
0199 ys = status_out(id,:);
0200 else
0201 y = status;
0202 ys = status_out;
0203 end
0204
0205 if plot_abs == 1, y = abs(y); end
0206
0207 y = y/max(ys);
0208 ys = ys/max(ys);
0209
0210 ymax = max(y(ix_trial(:,n)));
0211 ix = find(cond_id == n);
0212 NN = length(ix);
0213
0214 y_trg = [zeros(1, NN); repmat(ymax,1,NN)];
0215 y_status = repmat(status_val(n), 2, NN);
0216
0217 plot(t,y)
0218 hold on
0219 plot(t,ys,'-b')
0220 plot(trg_on(:,ix), y_trg ,'-r')
0221 if plot_status == 1
0222
0223 plot([trg_st(ix) ;trg_end(ix)], y_status ,'-r')
0224 end
0225 end
0226
0227 n1 = NXmax*(m-1) + 1;
0228 n2 = min(n1+NXmax, Ntrial);
0229 xlim([trg_st2(n1) trg_st2(n2)])
0230
0231 if m == Nfig
0232 xlim([trg_st2(n1) t(end)])
0233 end
0234 if ~isempty(Ymax)
0235 ylim([Ymin Ymax])
0236 end
0237
0238 nfig=nfig+1;
0239 end
0240 end
0241
0242
0243
0244
0245 function plot_multi_cond
0246 nfig = 1;
0247 npng = 0;
0248 figure;
0249
0250
0251 if Nch == Ncond
0252 Mcond = 1;
0253 else
0254 Mcond = Ncond;
0255 end
0256
0257 for ch=1:Nch
0258 y = status(ch,:);
0259 ys = status_out(ch,:);
0260
0261 if plot_abs == 1, y = abs(y); end
0262
0263 y = y/max(ys);
0264 ys = ys/max(ys);
0265
0266 for m=1:Nfig
0267 [nfig ,npng] = new_figure(nfig,npng);
0268 subplot(NY,NX,nfig);
0269
0270 for n=1:Mcond
0271 if Nch == Ncond
0272 n_cond = ch;
0273 else
0274 n_cond = n;
0275 end
0276
0277 ymax = max(y(ix_trial(:,n)));
0278 ix = find(cond_id == n_cond);
0279 NN = length(ix);
0280
0281 y_trg = [zeros(1, NN); repmat(ymax,1,NN)];
0282 y_status = repmat(status_val(n), 2, NN);
0283
0284 plot(t,y)
0285 hold on
0286 plot(t,ys,'-b')
0287 plot(trg_on(:,ix), y_trg ,'-r')
0288
0289 if plot_status == 1
0290
0291
0292 plot([trg_st(ix) ;trg_end(ix)], y_status ,'-r')
0293 end
0294 end
0295
0296 n1 = NXmax*(m-1) + 1;
0297 n2 = min(n1+NXmax, Ntrial);
0298 xlim([trg_st2(n1) trg_st2(n2)])
0299 if m == Nfig
0300 xlim([trg_st2(n1) t(end)])
0301 end
0302 if ~isempty(Ymax)
0303 ylim([Ymin Ymax])
0304 end
0305
0306
0307 nfig=nfig+1;
0308 end
0309 end
0310 end
0311
0312
0313
0314
0315 function [nfig ,npng] = new_figure(nfig,npng)
0316 if nfig > NX*NY
0317 nfig0 = ceil(NX/2);
0318 subplot(NY,NX,nfig0);
0319 title(['Status signal: ' fname],'Interpreter','none')
0320
0321 if ~isempty(plot_parm.png)
0322 npng = npng + 1;
0323 nstr = num2str(npng);
0324 print(gcf, '-dpng', [plot_parm.png '_' nstr '.png']);
0325 close
0326 end
0327 figure; nfig=1;
0328 end
0329 end
0330
0331
0332 function end_figure(npng)
0333 if ~isempty(plot_parm.png)
0334 nfig0 = ceil(NX/2);
0335 subplot(NY,NX,nfig0);
0336 title(['Status signal: ' fname],'Interpreter','none')
0337 npng = npng + 1;
0338 nstr = num2str(npng);
0339 print(gcf, '-dpng', [plot_parm.png '_' nstr '.png']);
0340 close
0341 end
0342
0343 end
0344
0345
0346 end
0347