Error code in gui

5 views (last 30 days)
sha
sha on 29 Oct 2012
Hi, i wanted to calculate between 3 textbox. and i have created this code. However, i have some error. and i cant figure out.
Code:
----------------------------------------
p = str2num(get (handles.load, ' String'));
d = str2num(get (handles.diameter, ' String'));
n = str2num(get (handles.fringe, ' String'));
f = ( (8 * p ) / (pi * d * n) );
set(handles.result, 'String', f);
------------------------------------------
The error:
------------------------------------------
??? Error using ==> get There is no ' String' property in the 'uicontrol' class.
Error in ==> New>calculationPushbutton_Callback at 387 p = str2num(get (handles.load, ' String'));
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> New at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)New('calculationPushbutton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
---------------------------------------
PLEASE HELP ME!!!
Thanks!

Accepted Answer

Pedro Villena
Pedro Villena on 29 Oct 2012
Edited: Pedro Villena on 8 Nov 2012
The sintaxis is good, but you left a space in the beginning of ' String'. Just erase the space blank that is before String
Fail code:
p = str2num(get (handles.load, ' String'));
d = str2num(get (handles.diameter, ' String'));
n = str2num(get (handles.fringe, ' String'));
Correct code:
p = str2num(get (handles.load, 'String'));
d = str2num(get (handles.diameter, 'String'));
n = str2num(get (handles.fringe, 'String'));
  1 Comment
Walter Roberson
Walter Roberson on 29 Oct 2012
Good catch, I didn't notice that.
The String property for a pushbutton is the label that will be used for the button, and would not usually be a numeric value. You need to be careful, though, as str2num() will take in a string and eval() it to try to get a number.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!