function status = mlq_vis( t, x, flag) % mlq_vis: visulalization for mlq.m % usage: options = odeset( 'OutputFcn', 'mlq_vis') % mlq_vis( tspan, x0, 'init') % status = mlq_vis( t, x); maybe multiple rows/columns % mlq_vis( [], [], 'done') global E T A mm status = 0; % Assume stop button wasn't pushed. if ischar( t) flag = t; % use first arg as flag else if nargin<3, flag = ''; end % ode standard end switch( flag) case 'init' figure( A.fig(1)); %odeplot( t, x, 'init'); case '' figure( A.fig(1)); %status = odeplot( t, x); case 'done' figure( A.fig(1)); %odeplot( t, x, 'done'); case 'pivot' figure( E.fig(1)); cla; E.hold = 1; for i=1:A.nm feval( E.vis, 0, A.xp(:,i), '', A.col(i,:)); end E.hold = 0; case 'mat' figure( A.fig(2)); for i=1:A.nm % linear dynamic model subplot( A.nm, 3, 3*i-2); ABc = [ mm(i).A, mm(i).B, mm(i).c]; sc = max( max( abs( ABc(:))), 0.1); imagesc( ABc, 1.2*[-sc,sc]); set( gca, 'Box','on', 'XTick',0.5+E.ns+[0,E.ni],... 'XTickLabel',[], 'YTick',0.5+(1:E.ns), 'YTickLabel', []); grid( 'on'); ylabel( sprintf( 'Mod%1d', i)); title( sprintf( '[%4.1f]', sc)); if i==A.nm, xlabel( 'A,B,c'); end % quadratic reward model subplot( A.nm, 3, 3*i-1); Qq = [ mm(i).Q, mm(i).q1, [mm(i).q0;zeros(E.ns-1,1)]]; sc = max( max( abs( Qq(:))), 0.1); imagesc( Qq, 1.2*[-sc,sc]); set( gca, 'Box','on', 'XTick',0.5+E.ns+[0,E.ni],... 'XTickLabel',[], 'YTick',0.5+(1:E.ns), 'YTickLabel', []); grid( 'on'); title( sprintf( '[%4.1f]', sc)); if i==A.nm, xlabel( 'Q,q1,q0'); end % LQ controller subplot( A.nm, 3, 3*i); PK = [ mm(i).P, mm(i).K', mm(i).xv]; sc = max( max( abs( PK(:))), 0.1); imagesc( PK, 1.2*[-sc,sc]); set( gca, 'Box','on', 'XTick',0.5+E.ns+[0,E.ni],... 'XTickLabel',[], 'YTick',0.5+(1:E.ns), 'YTickLabel', []); grid( 'on'); title( sprintf( '[%4.1f]', sc)); if i==A.nm, xlabel( 'P,K.xv'); end end case 'wave' figure( A.fig(1)); clf; rows = E.ns+E.ni+1; % predictions for r = 1:E.ns subplot( rows, 1, r); plot( T.t(1:T.i), T.dot(1:T.i,r), 'm', 'LineWidth', 3); grid( 'on'); set( gca, 'ColorOrder', A.col); hold('on'); plot( T.t(1:T.i), T.mdot(1:T.i,A.nm*(r-1)+(1:A.nm))); set(gca,'YLim',10*[E.smin(r),E.smax(r)]); ylabel( E.label(r,:)); end % actions for r = 1:E.ni subplot( rows, 1, E.ns+r); plot( T.t(1:T.i), T.act(1:T.i,r), 'm', 'LineWidth', 3); grid( 'on'); set( gca, 'ColorOrder', A.col); hold('on'); plot( T.t(1:T.i), T.mact(1:T.i,A.nm*(r-1)+(1:A.nm))); set(gca,'YLim',2*[E.imin(r),E.imax(r)]); ylabel( E.label(E.ns+r,:)); end % responsibility subplot( rows, 1, rows); mlq_vis( 'resp'); case 'resp' set( gca, 'ColorOrder', A.col); hold('on'); plot( T.t(1:T.i), T.resp(1:T.i,:)*0.8+repmat(1:A.nm,T.i,1), 'LineWidth', 2); grid( 'on'); set( gca,'YLim',[1,A.nm+1],'YTick', 1:A.nm); ylabel( 'Resp'); otherwise error( [' unknown flag: ', flag]); end %%%%