GUI 용 로그 박스를 만들려고 필사적으로 노력하고 있습니다. 내가하고 싶은 것은 처음에는 PUSH 버튼을 누른 후 목록에 텍스트를 쓰는 것입니다. PUSH 버튼의 콜백 기능은 다음과 같습니다.
function run__Callback(hObject, eventdata, handles)
initial_name=cellstr(get(handles.logbox1,'String'))
handles.names={'test','haus', 'top', 'down', 'optimistic'}
handles.names{end,end}=[] %Add Element for new text
handles.names{end,end}='neuuu' %Add Element
num_element=length(handles.names) %Count Elements
set(handles.logbox1,'String',handles.names) %Aktualisiere Liste
set(handles.logbox1,'Top',num_element) %Set Listbox to the last Element
목록 상자는 동일한 GUI에 있습니다. 그럼에도 불구하고 오류가 있습니다.
hg.uicontrol / set을 사용하여 rror
The name 'Top' is not an accessible property for an instance of class 'uicontrol'.
누구든지 제발 나를 도울 수 있습니까, 나는 무엇이 잘못되었는지 이해하지 못합니까?
감사합니다, John
당신 때문에 오류가있어 Top
하지 않은 것입니다 property
의 listbox uicontrol
; 또한는 Top
의 속성이 아닙니다 uicontrol
.
여기에서 uicontrol 속성 목록을 찾을 수 있습니다 .
"Top"에 가장 가까운 목록 상자 속성은 ListboxTop
입니다.
목록 상자에 대한 액세스를 관리하는 데 도움이 될 수있는 두 개의 간단한 GUI를 만들었습니다.
기본 GUI "add_to_listbox"에는 다음이 포함됩니다.
listbox
와 tag
에 ListBox1pushbutton
와 tag
pushbutton1은 String
"작업 추가"때마다 사용자가이를 밀어, 문자열을 같은 "메인 GUI가 : 삽입 된 문자열 #x를"이 같은 목록 상자의 상단에 추가됩니다 ( "X"는 conter입니다)pushbutton
와 tag
"open_subgui", String
"열기 SubGUI는"두 번째 GUI를 엽니 다SubGUI ( "add_to_listbox_subgui")에는 다음이 포함됩니다.
pushbutton
와 tag
pushbutton1, String
"메인 GUI에 작업 추가"때마다 사용자가이를 밀어, 문자열을 같은 메인 GUI 목록 상자의 상단에 추가 "SUB GUI 삽입 된 문자열 #x를"로 ( "X"는 conter입니다)SubGUI는 Main GUI listbox handle
에 저장된 Main GUi 를 사용하여 Main GUI 목록 상자에 문자열 추가를 처리합니다 guidata
(SubGUI가 Main GUI에 의해 열리면 Main GUI에 대한 입력으로 수신,이를 handle
통해 SubGUI 액세스 메인 GUI로 guidata
).
다음에서 찾을 수 있습니다.
OpeningFcn
"액션 카운터"가 초기화 된 메인 GUIpushbutton1_Callback
마다 목록 상자에 문자열을 추가하는 기본 GUIpushbutton
open_subgui_Callback
SubGUI를 여는 메인 GUIOpeningFcn
와 Main GUI guidata
가 모두 처리되는 SubGUIpushbutton1_Callback
마다 Main GUI 목록 상자에 문자열을 추가하는 SubGUIpushbutton
메인 GUI OpeningFcn
% --- Executes just before add_to_listbox is made visible.
function add_to_listbox_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 add_to_listbox (see VARARGIN)
% Choose default command line output for add_to_listbox
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes add_to_listbox wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Get Main GUI guidata
gui_data=guidata(gcf);
% Add (and initialize) button action counter to Main GUI guidata
gui_data.btn_action=0;
% Set Main GUI guidata
guidata(gcf,gui_data);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
메인 GUI pushbutton1_Callback
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Add button action (from Main GUI) string to the listbox
%
% Get Mani GUI guidata
gui_data=guidata(gcf);
% Increment button action counter
gui_data.btn_action=gui_data.btn_action+1;
% Set Main GUI guidata (to store button action counter)
guidata(gcf,gui_data);
% Generate action string and add it to the listbox
% The firt strimg is directly add to the listbox
if(gui_data.btn_action == 1)
new_str='Main GUI: Inserted string #1';
set(handles.listbox1,'string',new_str);
else
new_str=['Main GUI: Inserted string #' num2str(gui_data.btn_action)];
% The fisrt string in the list box is returned as "string", to add the
% second one, it has has to be first converted into a cellarray
if(gui_data.btn_action == 2)
tmp_str=cellstr(get(handles.listbox1,'string'));
else
% The order of the string in the listbox is reversed to have the last
% one on top
tmp_str=flipud(get(handles.listbox1,'string'));
end
% Set the updated set of seting to the listbox
tmp_str{end+1,1}=new_str;
set(handles.listbox1,'string',flipud(tmp_str));
end
메인 GUI open_subgui_Callback
% --- Executes on button press in open_subgui.
function open_subgui_Callback(hObject, eventdata, handles)
% hObject handle to open_subgui (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Open the Sub GUI; the handle of the Main GUI is passed as argument to
% This allows Sub GUI accessing to the Main GUI guidata
add_to_listbox_subgui(gcf)
% Disable the "Open Sub GUI" button
set(handles.open_subgui,'enable','off')
SubGUI OpeningFcn
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Add Sub GUI button action string to Main GUI listbox
%
% Get Sub GUI guidata
gui_data=guidata(gcf);
% Get Main GUI guidata, "gui_data.main_gui" holds the Main GUI handle
gui_data.main_gui_data=guidata(gui_data.main_gui);
% Increment the button action counter
gui_data.btn_action=gui_data.main_gui_data.btn_action+1;
% Update Main GUI button actin counter
main_gui_data=guidata(gui_data.main_gui);
main_gui_data.btn_action=gui_data.btn_action;
% Store Sub GUI guidata
guidata(gcf,gui_data);
% Store Main GUI guidata
guidata(gui_data.main_gui,main_gui_data);
%
% Add button action (from Main GUI) string to the listbox
%
if(gui_data.btn_action == 1)
% Generate action string and add it to the Main GUI listbox
% The firt strimg is directly add to the listbox
new_str='SUB GUI Inserted string #1';
set(gui_data.listbox,'string',new_str);
else
new_str=['SUB GUI Inserted string #' num2str(gui_data.btn_action)];
% The fisrt string in the list box is returned as "string", to add the
% second one, it has has to be first converted into a cellarray
if(gui_data.btn_action == 2)
tmp_str=cellstr(get(gui_data.listbox,'string'));
else
% The order of the string in the listbox is reversed to have the last
% one on top
tmp_str=flipud(get(gui_data.listbox,'string'));
end
% Set the updated set of seting to the listbox
tmp_str{end+1,1}=new_str;
set(gui_data.listbox,'string',flipud(tmp_str));
end
도움이 되었기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다