gpt4 book ai didi

MATLAB 多页 GUI 查询

转载 作者:太空宇宙 更新时间:2023-11-03 20:07:07 28 4
gpt4 key购买 nike

我目前正在为我已经完成的 m.file 开发一个 GUI。 GUI 将是一个具有多个页面的页面,每个页面都是一个独立的 GUI。

在主 GUI 上,用户将在具有 2 个选项的单选按钮组上进行选择。根据选择,页面顺序为主 GUI > GUI1 > GUI2 > GUI3,或主 GUI > GUI1 > GUI4 > GUI5。

引用“http://matlabbyexamples.blogspot.sg/2011/10/multipages-gui-forms-combining-from.html”中的示例,我以某种方式让它工作,我能够按预期从一个页面导航到另一个页面。

现在的问题是,每次我返回主 GUI 更改单选按钮组上的选择时,它都会重新打开所有 GUI 并关闭它们的可见性以再次隐藏它们(基本上是程序在我首先打开它),这不是我想要的。作为 MATLAB 的新用户,我不知道为什么会这样。

以下是我的master gui的代码段:

function varargout = StartPage(varargin)
% STARTPAGE MATLAB code for StartPage.fig
% STARTPAGE, by itself, creates a new STARTPAGE or raises the existing
% singleton*.
%
% H = STARTPAGE returns the handle to a new STARTPAGE or the handle to
% the existing singleton*.
%
% STARTPAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in STARTPAGE.M with the given input arguments.
%
% STARTPAGE('Property','Value',...) creates a new STARTPAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before StartPage_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to StartPage_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 StartPage

% Last Modified by GUIDE v2.5 14-Aug-2013 14:22:36

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

% Choose default command line output for StartPage
handles.output = hObject;
handles.s1 = InitialCostCalculation;
handles.s2 = PVSpecsInput;
handles.s3 = PVSummary;
handles.s4 = HybridSpecsInput;
handles.s5 = HybridSummary;

h1=guidata(handles.s1);
h1.next = handles.s4;
h1.prev = hObject;
guidata(handles.s1,h1);

h2=guidata(handles.s2);
h2.next = handles.s3;
h2.prev = handles.s1;
guidata(handles.s2,h2);

h3=guidata(handles.s3);
h3.prev = handles.s2;
guidata(handles.s3,h3);

h4=guidata(handles.s4);
h4.next = handles.s5;
h4.prev = handles.s1;
guidata(handles.s4,h4);

h5=guidata(handles.s5);
h5.prev = handles.s4;
guidata(handles.s5,h5);

% Update handles structure
guidata(hObject, handles);
handles.output;

set(handles.s1,'Visible','off');
set(handles.s2,'Visible','off');
set(handles.s3,'Visible','off');
set(handles.s4,'Visible','off');
set(handles.s5,'Visible','off');
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = StartPage_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 Pg1Start_Button.
function Pg1Start_Button_Callback(hObject, eventdata, handles)
% hObject handle to Pg1Start_Button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.output,'Visible','off');
set(handles.s1,'Visible','on');
set(handles.s2,'Visible','off');
set(handles.s3,'Visible','off');
set(handles.s4,'Visible','off');
set(handles.s5,'Visible','off');


% --- Executes when selected object is changed in MainMenu.
function MainMenu_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in MainMenu
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag')
case 'PV_Button'
h1=guidata(handles.s1);
h1.next = handles.s2;
h1.prev = StartPage;
guidata(handles.s1,h1);
case 'Hybrid_Button'
h1=guidata(handles.s1);
h1.next = handles.s4;
h1.prev = StartPage;
guidata(handles.s1,h1);
end


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

如果有人能让我知道我做错了什么并为我提供解决方案,我将不胜感激。

最佳答案

您可以使用以下文件交换程序 (uiremember/uirestore) 跟踪您的 gui 中的最后更改。此外,您可以通过使用“保存状态”例程填充 figure_closeRequestFcn()(或任何返回按钮回调)来实现此功能,如 here 所述。 .

关于MATLAB 多页 GUI 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18251269/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com