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

📄 qdis.m

📁 席位分配的matlab例程
💻 M
字号:
function varargout = qdis(varargin)
% QDIS M-file for qdis.fig
%      QDIS, by itself, creates a new QDIS or raises the existing
%      singleton*.
%
%      H = QDIS returns the handle to a new QDIS or the handle to
%      the existing singleton*.
%
%      QDIS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in QDIS.M with the given input arguments.
%
%      QDIS('Property','Value',...) creates a new QDIS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before qdis_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to qdis_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help qdis

% Last Modified by GUIDE v2.5 30-Oct-2007 21:31:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @qdis_OpeningFcn, ...
                   'gui_OutputFcn',  @qdis_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before qdis is made visible.
function qdis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to qdis (see VARARGIN)
%a_new = handles.metricdata.numa;
%b_new = handles.metricdata.numb;
%c_new = handles.metricdata.numc;

% Choose default command line output for qdis
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes qdis wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = qdis_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes during object creation, after setting all properties.
function a_new_CreateFcn(hObject, eventdata, handles)
% hObject    handle to a_new (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes during object creation, after setting all properties.
function b_new_CreateFcn(hObject, eventdata, handles)
% hObject    handle to b_new (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes during object creation, after setting all properties.
function c_new_CreateFcn(hObject, eventdata, handles)
% hObject    handle to c_new (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



function a_old_Callback(hObject, eventdata, handles)
% hObject    handle to a_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
numa = str2double(get(hObject, 'String'));
if isnan(numa)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
if ((numa-round(numa))~=0|numa<=0)
    set(hObject, 'String', 0);
    errordlg('Input must be a positive interge','Error');
end
% Save the new density value
handles.metricdata.numa = numa;
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of a_old as text
%        str2double(get(hObject,'String')) returns contents of a_old as a double


% --- Executes during object creation, after setting all properties.
function a_old_CreateFcn(hObject, eventdata, handles)
% hObject    handle to a_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function b_old_Callback(hObject, eventdata, handles)
% hObject    handle to b_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of b_old as text
%        str2double(get(hObject,'String')) returns contents of b_old as a double
numb = str2double(get(hObject, 'String'));
if isnan(numb)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
if ((numb-round(numb))~=0|numb<=0)
    set(hObject, 'String', 0);
    errordlg('Input must be a positive interge','Error');
end

% Save the new density value
handles.metricdata.numb = numb;
guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function b_old_CreateFcn(hObject, eventdata, handles)
% hObject    handle to b_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function c_old_Callback(hObject, eventdata, handles)
% hObject    handle to c_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
numc= str2double(get(hObject, 'String'));
if isnan(numc)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
if ((numc-round(numc))~=0|numc<=0)
    set(hObject, 'String', 0);
    errordlg('Input must be a positive interge','Error');
end
% Save the new density value
handles.metricdata.numc = numc;

guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of c_old as text
%        str2double(get(hObject,'String')) returns contents of c_old as a double


% --- Executes during object creation, after setting all properties.
function c_old_CreateFcn(hObject, eventdata, handles)
% hObject    handle to c_old (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% hObject    handle to calculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

a = handles.metricdata.numa;
b = handles.metricdata.numb;
c = handles.metricdata.numc;
tot=a+b+c;
new(1,1)=round(handles.metricdata.nn/tot*a);
new(2,1)=round(handles.metricdata.nn/tot*b);
new(3,1)=round(handles.metricdata.nn/tot*c);

dn=handles.metricdata.nn-new(1,1)-new(2,1)-new(3,1);
while(dn)
    [B,IX]=sort([a^2/new(1,1)/(new(1,1)+1),b^2/new(2,1)/(new(2,1)+1),c^2/new(3,1)/(new(3,1)+1)]);
    new(IX(length(B)),1)=new(IX(length(B)),1)+1;
    dn=dn-1;
end


set(handles.a_new, 'String', new(1,1));
set(handles.b_new, 'String', new(2,1));
set(handles.c_new, 'String', new(3,1));
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject    handle to reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.a_old, 'String', 0);
set(handles.b_old, 'String', 0);
set(handles.c_old, 'String', 0);
set(handles.a_new, 'String', 0);
set(handles.b_new, 'String', 0);
set(handles.c_new, 'String', 0);
set(handles.n_num, 'String', 0);




function n_num_Callback(hObject, eventdata, handles)
% hObject    handle to n_num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of n_num as text
%        str2double(get(hObject,'String')) returns contents of n_num as a double
nn = str2double(get(hObject, 'String'));
if isnan(nn)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
if ((nn-round(nn))~=0|nn<=0)
    set(hObject, 'String', 0);
    errordlg('Input must be a positive interge','Error');
end
handles.metricdata.nn = nn;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function n_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to n_num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


⌨️ 快捷键说明

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