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

📄 polgui_ver1_r14.m

📁 如何使用GUI那就下这个吧
💻 M
📖 第 1 页 / 共 3 页
字号:
% --- Executes during object creation, after setting all properties.function points_CreateFcn(hObject, eventdata, handles)% hObject    handle to points (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: listbox controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end%--------------------------------------------------------------------------% --- Executes on button press in remove.% Removes additional points and last digitized points onlyfunction remove_Callback(hObject, eventdata, handles)% hObject    handle to remove (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global special_case strmatch_index no_add LOC DATA DATA_TRANSF COUNTER COUNTER1;currentVal=get(handles.points,'Value');handles.data=DATA_TRANSF;handles.location=LOC;resultStr= get(handles.points,'String');numResults = size(resultStr,1);strmatch_index=strmatch(handles.location(currentVal,:),handles.needed_loc,'exact');if currentVal<numResults     uiwait(msgbox('User Can remove only the last digitized point','Error','error','modal'));else     if strmatch(handles.location(currentVal,:),handles.needed_loc,'exact') & (numResults<=4)        special_case=1;        str6=sprintf('\n\n\nGET POINT %s',handles.location(currentVal,:));        set(handles.text2,'String',str6);        resultStr(currentVal) =[];        handles.data(currentVal,:)=[];        handles.location(currentVal,:)=[];        DATA(currentVal,:)=[];        LOC(currentVal,:)=[];        COUNTER1=COUNTER1-3;        switch strmatch_index            case 1                set(handles.get_test,'Enable','on');            case 2                set(handles.get_la,'Enable','on');            case 3                set(handles.get_ra,'Enable','on');            case 4                set(handles.get_nasion,'Enable','on');         endelseif  strmatch(handles.location(currentVal,:),handles.needed_loc,'exact') & (numResults>4) & (numResults<=length(handles.needed_loc))    special_case==2;    set(handles.remove,'Enable','Off');else    pos_size = get(handles.figure1,'Position');    % Call remove_modaldlg_r14 with the argument 'Position'.        user_response = remove_modaldlg_r14('Title','Redigitize');        switch user_response        case {'No'}             special_case=3;             resultStr(currentVal) =[];             handles.data(currentVal,:)=[];             handles.location(currentVal,:)=[];             LOC(currentVal,:)=[];             if isequal(no_add,0)                   no_add=1;             else                 no_add=no_add+1;             end     % take no action        case 'Yes'     %              str7=sprintf('GET POINT %s',handles.location(currentVal,:));             set(handles.text2,'String',str7);             resultStr(currentVal) =[];             handles.data(currentVal,:)=[];             handles.location(currentVal,:)=[];             LOC(currentVal,:)=[];        end    end    COUNTER=COUNTER-1;       % % If there are no other entries, disable the Remove and Plot     % button    % and change the list sting to <empty>    if isequal(numResults,length(currentVal)),        resultsStr = {'<empty>'};        currentVal = 1;        set(handles.remove,'Enable','off')    end    % % Ensure that list box Value is valid, then reset Value and String    currentVal = min(currentVal,size(resultStr,1));    set(handles.points,'Value',currentVal,'String',resultStr)    % handles.location    % LOC    % handles.count    % Store the new ResultsData    guidata(hObject, handles);endguidata(hObject,handles);%--------------------------------------------------------------------------% --- Executes on button press in plot.% Plot data on seperate figure function plot_Callback(hObject, eventdata, handles)% hObject    handle to plot (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global DATA_TRANSF;status=get(handles.stop,'Enable');if isequal(status,'off')    load collected_data.mat;    DATA_TRANSF=data_transf;end plotColor = {'b','g','r','c','m','y','k'};Plotdata_x1=DATA_TRANSF(2:end,1);Plotdata_y1=DATA_TRANSF(2:end,2);Plotdata_z1=DATA_TRANSF(2:end,3);if ~isfield(handles,'PlotFigure') | ~ishandle(handles.PlotFigure),    handles.PlotFigure = figure('Name','Polhemus Digitizer',...        'Visible','off','NumberTitle','off',...        'HandleVisibility','off','IntegerHandle','off');    handles.PlotAxes = axes('Parent',handles.PlotFigure);    guidata(hObject, handles)end% Plot datapHandles = plot3(Plotdata_x1,Plotdata_y1,Plotdata_z1,'o','Parent',handles.PlotAxes);set(handles.PlotAxes,'BOX','on','XGrid','on','YGrid','on','ZGrid','on');xlabel(handles.PlotAxes,'X','Fontweight','bold','Fontsize',12);ylabel(handles.PlotAxes,'Y','Fontweight','bold','Fontsize',12);zlabel(handles.PlotAxes,'Z','Fontweight','bold','Fontsize',12);clear DATA_TRANSF% Make the figure visible and bring it forwardfigure(handles.PlotFigure)%--------------------------------------------------------------------------% Bytesavailable callback executes when the byte count reaches the one% specified in the handles.s.BytesAvailableFcnCount variable.function bytesavailablegui_callback(s,bytesavailable,handles)global DATA DATA_ORIG DATA_TRANSF COUNTER1 COUNTER additional redigitize  ;global LOC;global T M;global special_case strmatch_index no_add ; set(handles.points,'Value',1);data_str=fgetl(s); data_num=str2num(data_str); % Obtains data from digitizer when bytes-count % reaches the limit specified by BytesAvailableFcnCount% Format of data obtained for the current settings% 1 2 3 4 5 6 7% 1 ->01 Header% 2 ->X position in cms% 3-> Y position in cms% 4-> Z position in cms% 5-> Azimuth attitude in degrees% 6-> Elevation attitude in degrees% 7-> Roll attitude in degrees% Change for your specific device settingsdata_num(1,2:4); % Picks the X,Y,Z dataif isequal(additional,1) & COUNTER>4 % For additional points    DATA(COUNTER,1:3)=data_num(1,2:4);    handles.count=COUNTER;    DATA_TRANSF(COUNTER,1:3)=[data_num(1,2:4) 1]*T*M;    LOC=strvcat(LOC,num2str(COUNTER));    handles.data=DATA_TRANSF;    handles.location=LOC;    Plotdata_x=handles.data(handles.count,1);    Plotdata_y=handles.data(handles.count,2);    Plotdata_z=handles.data(handles.count,3);    if ~isequal(handles.count,1)          plot3(Plotdata_x,Plotdata_y,Plotdata_z,'p','Parent',handles.coordinates);         set(handles.coordinates,'BOX','on','XGrid','on','Ygrid','on','ZGrid','on');         hold(handles.coordinates,'on');         xlabel(handles.coordinates,'X','Fontweight','bold');         ylabel(handles.coordinates,'Y','Fontweight','bold');         zlabel(handles.coordinates,'Z','Fontweight','bold');    end    ResultsStr = get(handles.points,'String');    ResultsStr = [ResultsStr;{[handles.location(handles.count,:),'   :    ',...                num2str(handles.data(handles.count,1)),'   ',num2str(handles.data(handles.count,2)),'   ',num2str(handles.data(handles.count,3))]}];    set(handles.points,'String',ResultsStr);    str_text2=sprintf('\n\nPress Stylus Button to digitize additional points \n\n  OR\n\nPress STOP to finish digitization');    set(handles.text2,'String',str_text2);    COUNTER=COUNTER+1;%     handles.data    hObject=handles.get_additional;    guidata(hObject,handles);else     DATA_ORIG(COUNTER1,1:3)=data_num(1,2:4);       if rem(COUNTER1,3)==0 & COUNTER<=length(handles.needed_loc)           if (distance(DATA_ORIG(COUNTER1,:),DATA_ORIG(COUNTER1-1,:))>0.2)|(distance(DATA_ORIG(COUNTER1-1,:),DATA_ORIG(COUNTER1-2,:))>0.2)|(distance(DATA_ORIG(COUNTER1,:),DATA_ORIG(COUNTER1-2,:))>0.2)            redigitize=1; % For redigitization            COUNTER1=COUNTER1-3;            if COUNTER<5 % For test and cardinal points                errorstring=sprintf('Distance between succesive digitization greater than 2 mm\nRedigitize point %s\nPress OK to continue',handles.needed_loc(COUNTER,:));                uiwait(msgbox(errorstring,'Error','error','modal'));                switch COUNTER                  case 1                     set(handles.get_test,'Enable','on');                     set(handles.get_la,'Enable','off');                     str_text2=sprintf('\n\n\nGet Test Point');                     set(handles.text2,'String',str_text2);                 case 2                     set(handles.get_la,'Enable','on');                     set(handles.get_ra,'Enable','off');                     str_text2=sprintf('\n\n\nGet Cardinal Point LA');                     set(handles.text2,'String',str_text2);                 case 3                     set(handles.get_ra,'Enable','on');                     set(handles.get_nasion,'Enable','off');                     str_text2=sprintf('\n\n\nGet Cardinal Point RA');                     set(handles.text2,'String',str_text2);                 case 4                     set(handles.get_nasion,'Enable','on');                     set(handles.get_montage,'Enable','off');                     str_text2=sprintf('\n\n\nGet Cardinal Point NASION');                     set(handles.text2,'String',str_text2);                end                   DATA;            end        else              redigitize=0; % For all EEG Montage points             DATA(COUNTER,:)=(DATA_ORIG(COUNTER1,:)+DATA_ORIG((COUNTER1 -1),:)+DATA_ORIG((COUNTER1-2),:))/3;             switch COUNTER                   case 2                   str_la=sprintf('X = %2.3g cm\nY = %2.3g cm\nZ = %2.3g cm',DATA(2,1),DATA(2,2),DATA(2,3));                   set(handles.text_la,'String',str_la);                    case 3                    str_ra=sprintf('X = %2.3g cm\nY = %2.3g cm\nZ = %2.3g cm',DATA(3,1),DATA(3,2),DATA(3,3));                    set(handles.text_ra,'String',str_ra);                     case 4                    str_nasion=sprintf('X = %2.3g cm\nY = %2.3g cm\nZ = %2.3g cm',DATA(4,1),DATA(4,2),DATA(4,3));                    set(handles.text_nasion,'String',str_nasion);             end              handles.count=COUNTER;                if isequal(handles.count,1)                  if special_case==1                    LOC=strvcat(LOC,handles.needed_loc(strmatch_index,:));                    special_case=0;                  else                  LOC=strvcat(LOC,handles.needed_loc(COUNTER,:));                  end                elseif handles.count<size(handles.needed_loc,1)                if special_case==1                LOC=strvcat(LOC,handles.needed_loc(strmatch_index,:));                special_case=0;                else                 LOC=strvcat(LOC,handles.needed_loc(COUNTER,:));                end                elseif handles.count==size(handles.needed_loc,1)                if special_case==1                LOC=strvcat(LOC,handles.needed_loc(strmatch_index,:));                special_case=0;                else                 LOC=strvcat(LOC,handles.needed_loc(COUNTER,:));                 end                elseif special_case==3                LOC=strvcat(LOC,num2str(COUNTER+no_add));                 else                 LOC=strvcat(LOC,num2str(COUNTER));                end                handles.location=LOC;                handles.data=DATA;                if COUNTER==length(handles.needed_loc)                    str_text2=sprintf('\n\nGet Additional Points if needed');                    set(handles.text2,'String',str_text2);                end                  if handles.count>4                DATA_TRANSF(COUNTER,1:3)=[data_num(1,2:4) 1]*T*M;                handles.data=DATA_TRANSF;                end                Plotdata_x=handles.data(handles.count,1);                Plotdata_y=handles.data(handles.count,2);                Plotdata_z=handles.data(handles.count,3);                if ~isequal(handles.count,1)                    plot3(Plotdata_x,Plotdata_y,Plotdata_z,'p','Parent',handles.coordinates);                    set(handles.coordinates,'BOX','on','XGrid','on','Ygrid','on','ZGrid','on');                    hold(handles.coordinates,'on');                    xlabel(handles.coordinates,'X','Fontweight','bold');                    ylabel(handles.coordinates,'Y','Fontweight','bold');                    zlabel(handles.coordinates,'Z','Fontweight','bold');                end                COUNTER=COUNTER+1;                ResultsStr = get(handles.points,'String');                if isequal(handles.count,1)                ResultsStr = {[handles.location(handles.count,:),'   :   ',num2str(handles.data(1,1)),'   ',num2str(handles.data(1,2)),'   ',num2str(handles.data(1,3))]};                else                ResultsStr = [ResultsStr;{[handles.location(handles.count,:),'   :    ',...                num2str(handles.data(handles.count,1)),'   ',num2str(handles.data(handles.count,2)),'   ',num2str(handles.data(handles.count,3))]}];                end                   set(handles.points,'String',ResultsStr);          end    end    COUNTER1=COUNTER1+1;    handles.count=COUNTER;    handles.location=LOC;    hObject=handles.get_montage;    guidata(hObject,handles);    LOCend%--------------------------------------------------------------------------% Function to Calculate euclidean distance between digitized pointsfunction d=distance(X,Y)d=sqrt(sum((X-Y).^2));%--------------------------------------------------------------------------% --- Executes during object creation, after setting all properties.function logo_CreateFcn(hObject, eventdata, handles)% hObject    handle to logo (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: place code in OpeningFcn to populate logo%--------------------------------------------------------------------------

⌨️ 快捷键说明

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