Simple gui programing with pop-up manu.

4 次查看(过去 30 天)
Hello. I have the following simple GUI design.
The upper text box (which tag is input) is where the input number is entered while the lower text box (tag is output) presents the place where the output value appears.
The center pop-up menu (tag is select) has three calculation option with the input number; square, cubic and exponential. The output value calculated according to the choice of pop-up menu should be shown in the lower text box.
The corresponding m file is the following.
% --- Executes on selection change in select.
function select_Callback(hObject, eventdata, handles)
% hObject handle to select (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns select contents as cell array
% contents{get(hObject,'Value')} returns selected item from select
n = str2double(get(handles.input,'String')); % Obtaining number entered on the upper text box.
choice = get(hObject,'Value'); % Obtaining the selection from pop-up menu.
switch choice
case 1
y = n^2;
case 2
y = n^3;
case 3
y = exp(n);
end
set(handles.output,'string',y); % Print the output value at the lower text box
I didn't touch anything on the other part of the code.
I guessed there is no defect in this code unless I saw the error message like
Error using hg.figure/set
The name 'string' is not an accessible property for an instance of class
'figure'.
Error in practise_2>select_Callback (line 117)
set(handles.output,'string',y);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in practise_2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)practise_2('select_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
after the code running. Please tell me anything wrong on my code
In addition, could you tell me how I understand the command 'set'.
How is set used to give the output to the lower textbox?

采纳的回答

Dong-Gyu Jang
Dong-Gyu Jang 2014-2-25
You guys I finally dealt with the problem.
The write down the code again in changing the tag name by adding number 1, for example, I changed the tag name of pop-up menu as 'select' to 'select1' and other tag names are changed in this way.
There is no errors occurs and I can conclude that the it is recommended that the tag name should made such that possible coincidence to the Matlab built-in name is avoided.
Thanks to take an attention to my inquiry! Thanks!!

更多回答(1 个)

Image Analyst
Image Analyst 2014-2-25
Looks like y is a number so if you want to send a string to the edit box, you should use num2str:
set(handles.output,'string', num2str(y));
or you can probably do
set(handles.output,'Value',y);
Also, usually GUIDE creates output automatically so I never use it. Maybe there's some conflict. You might try calling it output1 or something instead.
  2 个评论
Dong-Gyu Jang
Dong-Gyu Jang 2014-2-25
Thanks for feedback but the code still gives the same message.
It is already confirmed that the code is good except for the last code
set(handles.output,'string',y); % Print the output value at the lower text box
I even tried to follow your advise like changing original tag 'output' to 'output1' and converting number to string by adding num2str command on the code but still have the error.
Could you give me your other possible suspect to this error?
Image Analyst
Image Analyst 2014-2-25
If you attach your m-file and fig-file, I might have time to look at it tomorrow.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by