⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vis_trajgui.m

📁 it is matlab code , som(slef organizing map) tool for matlab
💻 M
📖 第 1 页 / 共 3 页
字号:
function vis_trajgui(trajStruct,arg)% VIS_TRAJGUI subfuntion for SOM_TRAJECTORY%% This function is the actual GUI called by SOM_TRAJECTORY% function. %% See also SOM_TRAJECTORY.% Contributed code to SOM Toolbox 2.0, February 11th, 2000 by Juha Parhankangas% Copyright (c) by Juha Parhankangas.% http://www.cis.hut.fi/projects/somtoolbox/        % Version 2.0beta juha 180699if nargin == 1  sM_h=trajStruct.figure;  if size(trajStruct.bmus,1) ~= 1 & size(trajStruct.bmus,2) ~= 1    fuzzy_traj(trajStruct,[]);    return;  end      if size(trajStruct.bmus,1) == 1 | size(trajStruct.bmus,2) == 1    udata.bmus = trajStruct.bmus;    udata.a_h=[findobj(get(sM_h,'Children'),'Tag','Uplane');...	       findobj(get(sM_h,'Children'),'Tag','Cplane')];    udata.sM_h=trajStruct.figure;    udata.traj=[];    data1 = trajStruct.primary_data;    if ~isempty(trajStruct.primary_names)      names=trajStruct.primary_names;    else      for i=1:size(data1,2)	names{i,1}=sprintf('Var%d',i);      end    end    udata.lattice=trajStruct.lattice;    form = 0.7*vis_patch(udata.lattice);    udata.msize = trajStruct.msize;    %%%%%%%%%%%%%%%%%%%%%%%%    %    % forming a patch object, which is placed above every component plane    %            l = size(form,1);        nx = repmat(form(:,1),1,prod(udata.msize));    ny = repmat(form(:,2),1,prod(udata.msize));        x=reshape(repmat(1:udata.msize(2),l*udata.msize(1),1),l,prod(udata.msize));    y=repmat(repmat(1:udata.msize(1),l,1),1,udata.msize(2));        if strcmp(udata.lattice,'hexa')      t = find(~rem(y(1,:),2));      x(:,t)=x(:,t)+.5;    end    x=x+nx;    y=y+ny;        colors=reshape(ones(prod(udata.msize),1)*[NaN NaN NaN],...		   [1 prod(udata.msize) 3]);        set(0,'CurrentFigure',udata.sM_h);        %%%%%%%%%%%%%%%%%%%%%%    %    % drawing patch    %    % caxis -commands keep the colormap of the original patch unchanged.    %        for i=1:length(udata.a_h)      udata.real_patch(i)=get(udata.a_h(i),'Children');      set(udata.real_patch(i),'ButtonDownFcn',...			'vis_trajgui([],''click'')');      subplot(udata.a_h(i));      v=caxis;      udata.tmp_patch(i)=patch(x,y,colors,'EdgeColor','none',...			       'ButtonDownFcn',...			       'vis_trajgui([],''click'')',...			       'Tag','TmpPatch');      caxis(v);    end        %%%%%%%%%%%%%%%%%%%%                udata.length_of_traj=length(trajStruct.size);    udata.size=trajStruct.size;    udata.color=trajStruct.color;    udata.poly.x=[];    udata.poly.y=[];    udata.poly.h=[];    udata.new_marks=[];    udata.all_marks=[];    udata.d_mark2=[];    udata.fig1 = figure;    set(udata.fig1,'KeyPressFcn','vis_trajgui([],''key'')',...		   'Name','Primary Data');            %%%%%%%%%%%%%%%%%%%%    %    % making the 'Tools' -menu    %        udata.m_i=uimenu(udata.fig1,'Label','Trajectoy T&ools');    udata.m_i(2)=uimenu(udata.m_i,'Label','&Remove Trajectory',...			'Callback',...			'vis_trajgui([],''remove_traj'')');    udata.m_i(3)=uimenu(udata.m_i(1),'Label','&Dye Nodes',...			'Callback',...			'vis_trajgui([],''dye_gui'')');    udata.m_i(4)=uimenu(udata.m_i(1),'Label','&Clear Markers',...			'Callback',...			'vis_trajgui([],''clear'')');    udata.m_i(5)=uimenu(udata.m_i(1),'Label','&Save',...			'Callback',...			'vis_trajgui([],''save'')');    udata.m_i(6)=uimenu(udata.m_i(1),'Label','&Load',...			'Callback',...			'vis_trajgui([],''load'')');    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    %    % drawing data components to the figure ....    %    %         if nargin < 5 | isempty(comps) | (isstr(comps) & strcmp(comps,'all'))      comps = 1:size(data1,2);    end        x=1:size(data1,1);        for i=1:length(comps)      subplot(length(comps),1,i);      udata.h(i)=gca;      udata.d_mark(i).h=[];            udata.d(i)=plot(x,data1(:,comps(i)),...		      'ButtonDownFcn',...		      'vis_trajgui([],''line_down'')');              set(gca,'XLim',[1 size(data1,1)],...	      'XTick',[],...	      	      'ButtonDownFcn','vis_trajgui([],''line_down'')'); %,...	      %'YLim',[min(data1(:,comps(i))) max(data1(:,comps(i)))]);	            ylabel(names{comps(i)});      hold on;      ymin=get(udata.h(i),'YLim');      pos=mean(get(udata.h(i),'XLim'));      udata.l(i) = line([pos pos],[ymin(1) ymin(2)],...			'Color','red',...			'ButtonDownFcn',...			'vis_trajgui([],''down'')');    end    udata.text1=[];        udata.fig2=[];    udata.h2=[];    udata.l2=[];    udata.text2=[];        %%%%%%%%%%%%%%%%%%%%%%%%%%%    %    % ... and to the figure 2.    %            if ~isempty(trajStruct.secondary_data)      data2=trajStruct.secondary_data;      if isempty(trajStruct.secondary_names)	for i=1:size(data1,2)	  names2{i,1}=sprintf('Var%d',i);	end      else	names2=trajStruct.secondary_names;      end            udata.fig2 = figure;      set(udata.fig2,'Name','Secondary Data');      set(udata.fig2,'KeyPressFcn',...		     'vis_trajgui([],''key'')');      for i=1:size(data2,2)	subplot(size(data2,2),1,i);	udata.h2(i) = gca;	udata.d_mark2(i).h=[];	udata.d2(i) = plot(x,data2(:,i),...			   'ButtonDownFcn',...			   'vis_trajgui([],''line_down'')');	set(gca,'XLim',[1 size(data1,1)],'XTick',[],'ButtonDownFcn',...		'vis_trajgui([],[],[],[],[],[],''line_down'')');	ylabel(names2{i});	hold on;	ymin = get(udata.h2(i),'YLim');	pos = mean(get(udata.h2(i),'XLim'));	udata.l2(i) = line([pos pos],ymin,'Color','red',...			   'ButtonDownFcn','vis_trajgui([],''down'')');      end    end          %%%%%%%%%%%%%%%%%%%%%%%%%%        set(udata.fig1,'UserData',udata);    if ~isempty(udata.fig2);      tmp.fig1=udata.fig1;      set(udata.fig2,'UserData',tmp);    end    tmp=get(udata.sM_h,'UserData');    tmp.fig1=udata.fig1;    set(udata.sM_h,'UserData',tmp);      set_numbers(round(pos));     return;  end  end%%%%%%%%%%%%%%%%%%% if figures have been drawn, the only function calls that may exist% are the ones that change the state of the application.%udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');switch arg case 'fuzzy'  fuzzy_traj(tS,[]);  return; case 'move_fuzzy'  fuzzy_traj([],'move');  return; case 'remove_traj'  remove_traj;  return; case 'line_down'  line_bdf('down');  return; case 'line_drag'  line_bdf('drag');  return; case 'line_up'  line_bdf('up');  return; case 'dye_gui';  color_gui(udata.fig1);  return; case {'dye','cyan','magenta','yellow','red','green','blue','white','grey'}  dye_nodes(arg);  return; case 'clear'  clear_markers;  return; case 'key'  key_bdf;  return;    case 'click'  click;  return; case 'save'  save_data;  return; case 'load'  load_data;  return;end%%%%%%%%%%%% lines in the data figure(s) are dragged ...%udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');lims=get(gca,'XLim');x = getfield(get(gca,'CurrentPoint'),{1});  % the location of the lineif x < lims(1)  x=lims(1);elseif x > lims(2)  x=lims(2);endold = gcf;switch arg case 'down',...        % mouse button is pressed down above the line    set(gcf,'WindowButtonMotionFcn','vis_trajgui([],''drag'')');  set(gcf,'WindowButtonUpFcn','vis_trajgui([],''up'')');  set(udata.l,'EraseMode','xor');  delete(udata.text1);  if ~isempty(udata.l2);    set(udata.l2,'EraseMode','xor');    delete(udata.text2);  end  set(gcf,'Pointer','crosshair');   case 'drag'  % change the location of the lines    set(0,'CurrentFigure',udata.fig1);  set(udata.l,'XData',[x x]);  if ~isempty(udata.fig2)    set(0,'CurrentFigure',udata.fig2);    set(udata.l2,'XData',[x x]);  end  draw_traj(round(x));  set(0,'CurrentFigure',old); case 'up'    % draw trajectory and set figure to the normal state.    set(udata.l,'EraseMode','normal');  set(gcf,'Pointer','arrow','WindowButtonMotionFcn','',...	  'WindowButtonUpFcn','');  draw_traj(round(x));  set_numbers(round(x));end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function draw_traj(point)udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');color=udata.color;eMode='normal';if isstr(udata.color) & strcmp(udata.color,'xor')  eMode='xor';  color='black';endind=udata.bmus(point);[i j] = ind2sub(udata.msize,ind);if ~mod(i,2)  j=j+0.5;endold = gcf;set(0,'CurrentFigure',udata.sM_h);hold on;if isempty(udata.traj) | length(udata.traj.h) ~= length(udata.a_h)    % trajectory does not exist    for i=1:length(udata.a_h)    subplot(udata.a_h(i));    hold on;    new.h = plot(j,i,'Color',color,'EraseMode',eMode,'LineStyle','none');    udata.traj.h(i)=new;    udata.traj.j=j;    udata.traj.i=i;  endelse  if length(udata.traj.j) == udata.length_of_traj    % if the length of trajectory == ...,     udata.traj.j(1) = [];         % the first (the oldest) coordinate pair    udata.traj.i(1) = [];         % is removed.  end  udata.traj.j=[udata.traj.j;j]; % the new point is added to the  udata.traj.i=[udata.traj.i;i]; % end of coordinate vectors (i and j)  for i=1:length(udata.a_h)    subplot(udata.a_h(i));            % remove the existing trajectory    delete(udata.traj.h(i).h);          % and plot the new one.    for j=1:length(udata.traj.j)      udata.traj.h(i).h(j)=plot(udata.traj.j(j),udata.traj.i(j),...				'Color',color,...				'EraseMode',eMode,'Marker','o','LineWidth',2,...				'MarkerSize',udata.size(udata.length_of_traj-j+1),...				'LineStyle','none');    end  endend set(0,'CurrentFigure',udata.fig1);set(udata.fig1,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function set_numbers(x);% This function writes the numbers beside of the pointer linesudata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');xlim = get(gca,'XLim');ylim = get(gca,'YLim');p = ylim(1) + 0.9*(ylim(2)-ylim(1));old = gcf;set(0,'CurrentFigure',udata.fig1);for i=1:length(udata.h)  subplot(udata.h(i));    % check if the text is placed to the left side of the line...    if abs(x-xlim(1)) > (abs(x-xlim(2)))    udata.text1(i)=text(x-1,p,sprintf('%d ->',x),...                        'VerticalAlignment','top',...                        'HorizontalAlignment','right',...                        'FontWeight','demi');  else        %  or to the right side.        udata.text1(i)=text(x+1,p,sprintf('<- %d',x),...			'VerticalAlignment','top',...			'FontWeight','demi');  endendif ~isempty(udata.fig2)  set(0,'CurrentFigure',udata.fig2);    for i=1:length(udata.h2)    subplot(udata.h2(i));        if abs(x-xlim(1)) > (abs(x-xlim(2)))      udata.text2(i)=text(x-1,p,sprintf('%d ->',x),...			  'VerticalAlignment','top',...			  'HorizontalAlignment','right',...			  'FontWeight','demi');    else      udata.text2(i)=text(x+1,p,sprintf('<- %d',x),...			  'VerticalAlignment','top',...			  'FontWeight','demi');    end  endendset(0,'CurrentFigure',old);set(udata.fig1,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function remove_traj()% delete trajectory -object from every component plane.udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');if isempty(udata.traj)  return;endfor i=1:length(udata.traj.h)  delete(udata.traj.h(i).h);endudata.traj=[];set(udata.fig1,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function line_bdf(arg)% this function takes care of action when region is selected in the% data figure.udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');xlim=get(gca,'XLim');if ~(any(strcmp('THIS',fieldnames(udata))))  p = getfield(get(gca,'CurrentPoint'),{1});else  p = getfield(get(udata.THIS,'CurrentPoint'),{1});endif p < xlim(1)  p = xlim(1);elseif p > xlim(2)  p = xlim(2);endswitch arg case 'down'    % the mouse button is pressed down, the pointer lines are drawn.  % and the state of the figure is changed.    udata.THIS=gca;  set(gcf,'WindowButtonMotionFcn',...	  'vis_trajgui([],''line_drag'')',...	  'WindowButtonUpFcn','vis_trajgui([],''line_up'')');  udata.start_p=p;    old = gcf;  set(0,'CurrentFigure',udata.fig1);    for i=1:length(udata.h)    subplot(udata.h(i));    udata.t_line.h(i)=line([p p],get(gca,'YLim'),'Color','red');    udata.t_line.h2(i)=line([p p],get(gca,'YLim'),'Color','red',...			    'EraseMode','xor');  end  if ~isempty(udata.h2)    set(0,'CurrentFigure',udata.fig2);    for i=1:length(udata.h2)      subplot(udata.h2(i));      udata.t_line2.h(i)=line([p p],get(gca,'YLim'),'Color','red');      udata.t_line2.h2(i)=line([p p],get(gca,'YLim'),'Color','red',...			       'EraseMode','xor');    end  end   case 'drag'    % change the position of the pointer lines    old = gcf;  set(0,'CurrentFigure',udata.fig1);  set(udata.t_line.h2,'XData',[p p]);  if ~isempty(udata.fig2)    set(0,'CurrentFigure',udata.fig2);    set(udata.t_line2.h2,'XData',[p p]);  end  set(0,'CurrentFigure',old); case 'up'      % sort the 'points' -vector and draw the markers to the data and nodes    points=sort([round(udata.start_p) round(p)]);  draw_markers(points(1):points(2));  udata=get(udata.fig1,'UserData');  udata.new_marks=unique([udata.new_marks ;(points(1):points(2))']);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -