MATLAB Answers

GUIDE - guidata not working

조회 수: 5(최근 30일)
Lorenzo
Lorenzo 26 Jun 2013
Dear all; I don't have much of experience with guide so what I'm asking might be a real silly issue... I have a simple GUI in which I have a drop down menu and a table. Depending of what is chosen in the drop down menu, the first column of the table should be updated with different entries (Data1, Data2...) so that the user can fill the second column with the corresponding values for Data1, Data2 and so on... Now, I'm having problems with shared variables. The variable I want to share is handles.StraightPipe as this is supposed to hold the values for the first column of the table (the scrips is not ready to accomplish this yet). Now, if I move handles.StraightPipe around I can see its output on the editor unless I move it after function varargout, if that happens nothing is written on the editor meaning that at this point the variable is not recognized anymore and I don't undestand why.
Any help would be really appreciated
Here's my script:
function varargout = testToolbox(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testToolbox_OpeningFcn, ...
'gui_OutputFcn', @testToolbox_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 testToolbox is made visible.
function testToolbox_OpeningFcn(hObject, eventdata, handles, varargin)
handles.StraightPipe = {'Straight_diameter';'Straight_length1';'Shape'};
handles.Turn = {'Turn Angle','Turn Diameter'};
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = testToolbox_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%--- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
%something goes here
% --- Executes during object creation, after setting all properties.
function uitable1_CreateFcn(hObject, eventdata, handles)
set(hObject,'ColumnName','Value','RowName',{'a';'b';'c'},'Data',{blanks(0);blanks(0);blanks(0)});

  댓글 수: 2

David Sanchez
David Sanchez 26 Jun 2013
what do you mean by " if I move handles.StraightPipe around " ?
Lorenzo
Lorenzo 26 Jun 2013
Hi David and thank you for your question. As you can see I define handles.StraightPipe right after function testToolbox_OpeningFcn. Now, to understand where the problem is generating, I try to copy handles.StraightPipe (without semi column) at different positions of the script, this way I can get the output of it on the editor. Now, if I paste it at every position before function varargout then I keep having the output otherwise no output meaning that at some position I'm losing it.... Please let me know in case this is still not clear.
Thanks again

로그인 to comment.

답변 수 (2)

Tom
Tom 26 Jun 2013
It doesn't work because you're changing the handle itself, so the program can no only reference the controls. I'm guessing you should be doing something like this:
set(handles.StraightPipe,'String',{'Straight_diameter';'Straight_length1';'Shape'});
set(handles.Turn,'String'({'Turn Angle','Turn Diameter'});

  댓글 수: 4

표시 이전 댓글 수: 1
Tom
Tom 26 Jun 2013
You should add the code I suggests after the guidata line on the OpeningFcn - don't touch anything before that.
Tom
Tom 26 Jun 2013
Looking at your code, what are StraightPipe and StraightDiameter meant to be? I assumed they were uicontrols, but they seem to be called popupmenu1 and uitable1.
Lorenzo
Lorenzo 26 Jun 2013
Nope, still not working.... handles.StraightPipe should hold a certain amount of strings to be used as names of the rows for a table.

로그인 to comment.


Lorenzo
Lorenzo 26 Jun 2013
I guess my problem is that probably I haven't understood how nested functions work... Also: how can I update the table values once the user has made his choice among the drop down menu entries?
Thanks again everybody.

  댓글 수: 4

표시 이전 댓글 수: 1
Lorenzo
Lorenzo 26 Jun 2013
Nothing happens....maybe I should put the question in another way as my code may be totally wrong: I have a popup and a table. Depending on what's the user choice in the popup, the RowName properties for the table changes. How would you accomplish that?
Thanks again!
Tom
Tom 26 Jun 2013
I just tried it by creating a similar GUI and it works for me, so I can't say what the issue is. I would post the second part as a new question for clarity.
Lorenzo
Lorenzo 26 Jun 2013
Right! I'll do that, thank you!

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by