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

📄 powernetwork1_gui.m

📁 通过MATLAB编程实现自动输出A矩阵
💻 M
字号:
function varargout = powernetwork1_gui(varargin)
% POWERNETWORK1_GUI M-file for powernetwork1_gui.fig
%      POWERNETWORK1_GUI, by itself, creates a new POWERNETWORK1_GUI or raises the existing
%      singleton*.
%
%      H = POWERNETWORK1_GUI returns the handle to a new POWERNETWORK1_GUI or the handle to
%      the existing singleton*.
%
%      POWERNETWORK1_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in POWERNETWORK1_GUI.M with the given input arguments.
%
%      POWERNETWORK1_GUI('Property','Value',...) creates a new POWERNETWORK1_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before powernetwork1_gui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to powernetwork1_gui_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

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 23-Jan-2009 20:41:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @powernetwork1_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @powernetwork1_gui_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 powernetwork1_gui is made visible.
function powernetwork1_gui_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 powernetwork1_gui (see VARARGIN)

set (handles.edit1,'String',strvcat('Please input the count of nodes in','      the blank below and then push ','the input button.'));

% Choose default command line output for powernetwork1_gui
handles.number_click = 0;
guidata(hObject,handles);
handles.output_click = 0;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = powernetwork1_gui_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 on button press in input.
function input_Callback(hObject, eventdata, handles)
% hObject    handle to input (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.number_click = handles.number_click+1;
guidata(hObject,handles);
if  handles.number_click == 1
    handles.row = handles.data;
    guidata(hObject,handles);
    set (handles.edit1,'String',strvcat('Please input the count of branches','  in the blank below and then','push the input button.'));
    set (handles.edit2,'String','');
elseif handles.number_click == 2
    handles.column = handles.data;
    guidata(hObject,handles);
    display1 = 'Please input the connection sequence';
    display2 = 'using the format:[ ; ].';
    display3 = 'Branch Number: ';
    display = double(display3);
    display(1,16) = double(num2str(handles.number_click-1));
    display = char(display);
    set(handles.edit1,'String',strvcat(display1,display2,display));
    set (handles.edit2,'String','');
    handles.A = zeros(handles.row,handles.column);
    guidata(hObject,handles);
else
    A = eval(handles.character);
    i = A(1,1);
    j = A(2,1);
    handles.A(i,handles.number_click-2) = 1;
    guidata(hObject,handles);
    handles.A(j,handles.number_click-2) = -1;
    guidata(hObject,handles);
    set(handles.edit2,'String','');
    display1 = 'Please input the connection sequence';
    display2 = 'using the format:[ ; ].';
    display3 = 'Branch Number: ';
    display = double(display3);
    display(1,16) = double(num2str(handles.number_click-1));
    display = char(display);
    set(handles.edit1,'String',strvcat(display1,display2,display));
end

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

handles.output_click = handles.output_click+1;
guidata(hObject,handles);
if handles.output_click == 1
    if handles.row == 1
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:))));
    elseif handles.row == 2
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:))));
    elseif handles.row == 3
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:))));
    elseif handles.row == 4
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:))));
    elseif handles.row == 5
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:))));
    elseif handles.row == 6
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:))));
    elseif handles.row == 7
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:))));
    elseif handles.row == 8
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:)),int2str(handles.A(8,:))));
    elseif handles.row == 9
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:)),int2str(handles.A(8,:)),int2str(handles.A(9,:))));
    elseif handles.row == 10
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:)),int2str(handles.A(8,:)),int2str(handles.A(9,:)),int2str(handles.A(10,:))));
    elseif handles.row == 11
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:)),int2str(handles.A(8,:)),int2str(handles.A(9,:)),int2str(handles.A(10,:)),int2str(handles.A(11,:))));
    elseif handles.row == 12
        set(handles.edit2,'String',strvcat(int2str(handles.A(1,:)),int2str(handles.A(2,:)),int2str(handles.A(3,:)),int2str(handles.A(4,:)),int2str(handles.A(5,:)),int2str(handles.A(6,:)),int2str(handles.A(7,:)),int2str(handles.A(8,:)),int2str(handles.A(9,:)),int2str(handles.A(10,:)),int2str(handles.A(11,:)),int2str(handles.A(12,:))));
    end
elseif handles.output_click == 2
    [rows,cols] = size(handles.A);
    T = zeros(rows,1);
    t = -1;
    if rows == 1
        T(1,1) = 1;
    else
        for m = 1:rows-1   %起点搜索(只要已经作过起点的节点不作终点,则生成的树不同)。
            for n = 1:cols   %(已知节点数大于1)搜索与节点m相连的支路;每次重新读入A矩阵;与m相连的每一条支路都将成为一棵树,每找到一条这样的支路,在T中新开辟一列,存入m到对应位置。
                A = handles.A;
                if A(m,n) ~= 0
                    t1 = -1;
                    t = t+1;
                    if t > 0
                        [i,j] = size(T);
                        j = j+1;
                        T(1,j) = m;
                    else
                        [i,j] = size(T);
                        T(1,j) = m;
                    end
                    for m1 = 1:rows   % 行搜索;寻找第n列中与起点m相连接的节点m1;将m1存入T中与m对应的列;删去A中第n列。
                        if (A(m1,n) ~= 0) && (m1 ~= m)
                            T(2,j) = m1;
                            if rows > 2   % 若节点数大于2,则继续搜索与节点m1相连的其它支路。
                                A(:,n) = [];
                                [r1,c1] = size(A);
                                for n1 = 1:c1   %搜索与节点m1相连的支路;每次重新读入A1矩阵;与m1相连的每一条支路都将成为一棵树,每找到一条这样的支路,在T中新开辟一列,存入m,m1到对应位置。
                                    A1 = A;
                                    if A1(m1,n1) ~= 0
                                        t1 = t1+1;
                                        if t1 > 0
                                            [i1,j1] = size(T);
                                            j1 = j1+1;
                                            T(1,j1) = m;
                                            T(2,j1) = m1;
                                        else
                                            [i1,j1] = size(T);
                                            T(2,j1) = m1;
                                        end
                                        for m2 = 1:rows
                                            if (A1(m2,n1) ~= 0) && (m2 ~= m1)
                                                T(3,j1) = m2;
                                                
                                                if rows > 3
                                                    
                                                end
                                            end
                                        end
                                    end
                                end
                            end         
                        end
                    end
                end    
            end    
        end
    end
    set(handles.edit2,'String',int2str(T'));
    set(handles.edit1,'String',strvcat('The following output shows','all of trees of a diagram.'));
else
    set(handles.edit1,'String',strvcat(' ','Please close the window.'));
end
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



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

handles.data = str2double(get(handles.edit2,'String'));
guidata(hObject,handles);
handles.character = get(handles.edit2,'String');
guidata(hObject,handles);

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


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


⌨️ 快捷键说明

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