Error code in gui

4 visualizzazioni (ultimi 30 giorni)
sha
sha il 29 Ott 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!

Risposta accettata

Pedro Villena
Pedro Villena il 29 Ott 2012
Modificato: Pedro Villena il 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 Commento
Walter Roberson
Walter Roberson il 29 Ott 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by