?? vis_trajgui.m
字號:
case {'normal','alt'} draw_poly; case 'extend' click_node;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function click_node()% takes care of the action, when the middle mouse button is% pressed (mouse pointer is above some component plane).udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');new_marks=[];old=gcf;NEW=0;AGAIN = 0;coords=get(gca,'CurrentPoint');row=round(coords(1,2));if strcmp(udata.lattice,'hexa') & ~mod(row,2) col = round(coords(1,1) - 0.5);else col = round(coords(1,1));endind = sub2ind(udata.msize,row,col);new_marks=find(udata.bmus==ind);if strcmp(get(gcbo,'Tag'),'TmpPatch'); % if the callback is made via temporary patch object, node is marked % (node is black) => the mark is to be removed node_color = getfield(get(gcbo,'FaceVertexCData'),{ind,[1:3]}); AGAIN = 1;endfor i=1:length(udata.tmp_patch) color = get(udata.tmp_patch(i),'FaceVertexCData'); if length(size(color)) ~= 2 color = reshape(color,[size(color,1) 3]); end if all(isnan(color(ind,:))) NEW=1; color(ind,:)=[0 0 0]; else color(ind,:)=[NaN NaN NaN]; end set(udata.tmp_patch(i),'FaceVertexCData',color);endset(0,'CurrentFigure',udata.fig1);for j=1:length(udata.h) subplot(udata.h(j)); if NEW y=getfield(get(udata.d(j),'YData'),{new_marks}); udata.d_mark(j).h=[udata.d_mark(j).h;plot(new_marks,y,'Color',[0 0 0],... 'LineStyle','none',... 'Marker','o')]; endendif ~isempty(udata.fig2) set(0,'CurrentFigure',udata.fig2); for j=1:length(udata.h2); subplot(udata.h2(j)); if NEW y=getfield(get(udata.d2(j),'YData'),{new_marks}); udata.d_mark2(j).h=[udata.d_mark2(j).h;plot(new_marks,y,... 'LineStyle','none',... 'Color','black',... 'Marker','o')]; end endendif NEW udata.new_marks=[udata.new_marks; new_marks];endif AGAIN % find marks from the data that map to the clicked node. if the color % of the mark(s) is the same as the node's color, remove mark(s), else % let mark be unchanged. for i=1:length(udata.d_mark(1).h) if all(node_color==get(udata.d_mark(1).h(i),'Color')) tmp1 = get(udata.d_mark(1).h(i),'XData'); tmp2 = setdiff(tmp1,new_marks); if length(tmp1) ~= length(tmp2) inds=[]; for j=1:length(tmp2); inds=[inds find(tmp2(j)==tmp1)]; end for j=1:length(udata.d_mark) ydata=getfield(get(udata.d_mark(j).h(i),'YData'),{inds}); set(udata.d_mark(j).h(i),'XData',tmp2,'YData',ydata); end if ~isempty(udata.fig2) for j=1:length(udata.d_mark2) ydata=getfield(get(udata.d_mark2(j).h(i),'YData'),{inds}); set(udata.d_mark2(j).h(i),'XData',tmp2,'YData',ydata); end end end end end udata.new_marks=setdiff(udata.new_marks, new_marks); udata.all_marks=setdiff(udata.all_marks,new_marks);endset(udata.fig1,'UserData',udata);set(0,'CurrentFigure',old);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function draw_poly()udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');if isempty(udata.poly.x) if strcmp(get(gcf,'SelectionType'),'alt') return; end udata.poly.THIS = gca;end% 'THIS' indicates what was the axes where the polygon was meant to% drawn. It is not possible to add points, that lie in another axes, to the% polygon.if gca ~= udata.poly.THIS return;endcoords(1,1) = getfield(get(gca,'CurrentPoint'),{3});coords(1,2) = getfield(get(gca,'CurrentPoint'),{1});udata.poly.x=cat(1,udata.poly.x,coords(2));udata.poly.y=cat(1,udata.poly.y,coords(1));%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% remove old 'polygon' from axisdelete(udata.poly.h);switch get(gcf,'SelectionType') case 'normal' % add point to the 'polygon' and draw it for i=1:length(udata.a_h) subplot(udata.a_h(i)); hold on; udata.poly.h(i) = plot(udata.poly.x,udata.poly.y,'black',... 'EraseMode','xor',... 'ButtonDownFcn',... 'vis_trajgui([],''click'')',... 'LineWidth',2); end case 'alt' % The polygon is ready. udata.poly.x=cat(1,udata.poly.x,udata.poly.x(1)); udata.poly.y=cat(1,udata.poly.y,udata.poly.y(1)); for i=1:length(udata.a_h) subplot(udata.a_h(i)); udata.poly.h(i) = plot(udata.poly.x,udata.poly.y,'black',... 'EraseMode','xor',... 'ButtonDownFcn',... 'vis_trajgui([],''click'')',... 'LineWidth',2); end tmp=sort(repmat((1:udata.msize(1))',udata.msize(2),1)); tmp(:,2)=repmat((1:udata.msize(2))',udata.msize(1),1); tmp2=tmp; if strcmp(udata.lattice,'hexa'); t=find(~rem(tmp(:,1),2)); tmp(t,2)=tmp(t,2)+0.5; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % find the nodes that lie inside polygon and change coordinates to % linear indices. in = find(inpolygon(tmp(:,2),tmp(:,1),udata.poly.x,udata.poly.y)); in = sub2ind(udata.msize,tmp2(in,1),tmp2(in,2)); colors=get(udata.tmp_patch(1),'FaceVertexCData'); colors=reshape(colors,[size(colors,1) 3]); tmp=ones(length(in),1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % set the color of the nodes just selected, black. colors(in,:)=tmp*[0 0 0]; set(udata.tmp_patch,'FaceVertexCData',colors); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % find the points mapping to the nodes from data inds = []; for i=1:length(in) inds=[inds;find(in(i) == udata.bmus)]; end %%%%%%%%%%%%%%%%%%% % plot marks to data set(udata.fig1,'UserData',udata); plot2data(inds); udata=get(udata.fig1,'UserData'); udata.new_marks=union(udata.new_marks,inds); delete(udata.poly.h); udata.poly.h=[]; udata.poly.x=[]; udata.poly.y=[]; udata.poly.THIS=[];endset(udata.fig1,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function save_data()udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');data.points=[];data.nodes=[];k=1;for i=1:length(udata.d_mark(1).h) data.points(i).inds=get(udata.d_mark(1).h(i),'XData'); data.points(i).color=get(udata.d_mark(1).h(i),'Color');endcolor=get(udata.tmp_patch(1),'FaceVertexCData');color=reshape(color,[size(color,1) 3]);for i=1:size(color,1) if all(~isnan(color(i,:))) tmp.ind=i; tmp.color=color(i,:); data.nodes(k)=tmp; k=k+1; endendanswer=inputdlg('Enter the name of the output variable:','',1);if isempty(answer) | isempty(answer{1}) msgbox('Output is not set to workspace.'); return;else assignin('base',answer{1},data); disp(sprintf('Struct is set to the workspace as ''%s''.',answer{1}));end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function load_data()answer = inputdlg('Enter the name of the struct to be loaded:','',1);if isempty(answer) | isempty(answer{1}) msgbox('Data is not loaded.'); return;enddata=evalin('base',answer{1});if ~isstruct(data) errordlg('Input variable must be a struct.'); return;endtmp1 = fieldnames(data);tmp2 = {'nodes','points'};for i=1:length(tmp1) for j=1:length(tmp2); if ~any(strcmp(tmp2{j},tmp1)) errordlg('Wrong type of struct.'); return; end endendif ~isempty(data.points) tmp1=fieldnames(data.points(1));endif ~isempty(data.nodes) tmp2=fieldnames(data.nodes(1));endfor i=1:length(tmp1) if ~any(strcmp(tmp1{i},{'inds','color'})) errordlg('Wrong type of struct.'); return; endendfor i=1:length(tmp2) if ~any(strcmp(tmp2{i},{'ind','color'})) errordlg('Wrong type of struct.'); return; endendudata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');clear_markers;remove_traj;old = gcf;for i=1:length(data.points) for j=1:length(udata.h); set(0,'CurrentFigure',udata.fig1); subplot(udata.h(j)); ydata=getfield(get(udata.d(j),'YData'),{data.points(i).inds}); udata.d_mark(j).h=[udata.d_mark(j).h;... plot(data.points(i).inds,ydata,... 'Color',data.points(i).color,... 'LineStyle','none',... 'Marker','o',... 'ButtonDownFcn',... 'vis_trajgui([],''line_down'')')]; if all(data.points(i).color == [0 0 0]) udata.new_marks=unique([udata.new_marks; (data.points(i).inds)']); else udata.all_marks=unique([udata.all_marks; (data.points(i).inds)']); end end if ~isempty(udata.fig2) set(0,'CurrentFigure',udata.fig2); for j=1:length(udata.h2) subplot(udata.h2(j)); ydata=getfield(get(udata.d2(j),'YData'),{data.points(i).inds}); udata.d_mark2(j).h=[udata.d_mark2(j).h;... plot(data.points(i).inds,ydata,... 'Color',data.points(i).color,... 'LineStyle','none',... 'Marker','o',... 'ButtonDownFcn',... 'vis_trajgui([],''line_down'')')]; end endend set(0,'CurrentFigure',udata.sM_h);color=get(udata.tmp_patch(1),'FaceVertexCData');color=reshape(color,[size(color,1) 3]);for i=1:length(data.nodes) color(data.nodes(i).ind,:)=data.nodes(i).color;endfor i=1:length(udata.tmp_patch); set(udata.tmp_patch(i),'FaceVertexCData',color);endset(0,'CurrentFigure',old);set(udata.fig1,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function fuzzy_traj(trajStruct,arg); %function fuzzy_traj(sM_h,sM,sD,interval,arg)if isempty(arg) if strcmp(trajStruct.lattice,'hexa') udata.lattice='hexa'; udata.form=vis_patch('hexa'); else data.lattice='rect'; udata.form=vis_patch('rect'); end % interval=[1 size(trajStruct.primary_data,1)]; l=size(udata.form,1); dim = size(trajStruct.primary_data,2); udata.a_h=[findobj(get(trajStruct.figure,'Children'),'Tag','Uplane');... findobj(get(trajStruct.figure,'Children'),'Tag','Cplane')]; udata.sM_h=trajStruct.figure; udata.msize=trajStruct.msize; %%%%%%%%%%%%%%% % % constructing patch that is drawn above every plane in map % nx = repmat(udata.form(:,1),1,prod(udata.msize)); ny = repmat(udata.form(:,2),1,prod(udata.msize)); x_c=reshape(repmat(1:udata.msize(2),l*udata.msize(1),1),l,prod(udata.msize)); y_c=repmat(repmat(1:udata.msize(1),l,1),1,udata.msize(2)); if strcmp(udata.lattice,'hexa') t = find(~rem(y_c(1,:),2)); x_c(:,t)=x_c(:,t)+.5; end x_c=x_c+nx; y_c=y_c+ny; udata.orig_c=ones(prod(udata.msize),1)*[NaN NaN NaN]; colors=reshape(udata.orig_c,[1 size(udata.orig_c,1) 3]); set(0,'CurrentFigure',trajStruct.figure); %%%%%%%%% % drawing for i=1:length(udata.a_h); subplot(udata.a_h(i)); v=caxis; udata.patch_h(i) =patch(x_c,y_c,colors,'EdgeColor','none'); caxis(v); end udata.orig_x=get(udata.patch_h(1),'XData'); udata.orig_y=get(udata.patch_h(1),'YData'); % if interval(1) < 1 | interval(2) > size(trajStruct.primary_data,1) % error('Invalid argument ''interval''.'); % end x=1:size(trajStruct.primary_data,1); udata.fig1=figure; set(udata.fig1,'KeyPressFcn',... 'vis_trajgui([],''move_fuzzy'')'); for i=1:size(trajStruct.primary_data,2) subplot(size(trajStruct.primary_data,2),1,i); udata.h(i)=gca; set(udata.h(1),'XTick',[]); udata.d(i)=plot(x,trajStruct.primary_data(:,i)); l_x=1; lims(1) = round(min(trajStruct.primary_data(:,i))); lims(2) = round(max(trajStruct.primary_data(:,i))); udata.l(i) = line([l_x l_x],lims,'Color','red','EraseMode','xor'); end udata.l_x = l_x; udata.interval=[1 size(trajStruct.bmus,2)]; tmp.fig1=udata.fig1; % [K,P] = estimate_kernels(sM,sD); % udata.K=K; % udata.P=P; % udata.codebook=sM.codebook; % udata.data=sD.data; udata.bmus=trajStruct.bmus; set(udata.fig1,'UserData',udata); set(trajStruct.figure,'UserData',tmp); draw_fuzzy(l_x); return;endmove_fuzzy;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function draw_fuzzy(x)udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');inds = find(udata.bmus(:,x));[row col] = ind2sub(udata.msize,inds);if strcmp(udata.lattice,'hexa') t=find(~mod(row,2)); col(t)=col(t)+0.5;endcolor=udata.orig_c;color=reshape(color,[size(color,1) 3]);xdata=udata.orig_x;ydata=udata.orig_y;tmp= ones(size(xdata(:,1),1),1)*udata.bmus(inds,x)';color(inds,:) = ones(length(inds),1)*[0 0 0];xdata(:,inds) = udata.form(:,1)*ones(1,length(inds)).*tmp+ones(6,1)*col';ydata(:,inds) = udata.form(:,2)*ones(1,length(inds)).*tmp+ones(6,1)*row';set(udata.patch_h,'FaceVertexCData',color,'XData',xdata,'YData',ydata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function move_fuzzy% moves pointer lines and draws fuzzy response.udata=get(gcf,'UserData');udata=get(udata.fig1,'UserData');switch get(gcf,'CurrentCharacter'); case {'<','>'} key = get(gcf,'CurrentCharacter'); if key == '>' if udata.l_x + 1 > udata.interval(2) return; end l_x = udata.l_x + 1; else if udata.l_x - 1 < udata.interval(1) return; end l_x = udata.l_x - 1; end draw_fuzzy(l_x); set(udata.l,'XData',[l_x l_x]); udata.l_x=l_x; set(udata.fig1,'UserData',udata); otherwise return;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -