필터 지우기
필터 지우기

Error in calculation code

조회 수: 2 (최근 30일)
sha
sha 2012년 11월 6일
Hi there,
i have created a 3 text and a button in gui. once u click on the button, the calculation for the 3 text will be process and the final result will appear. And i wanted to do so 3 times. and the final result will appear at 3 individual box. however i have an error. here's my code :
-----------------------------------------------------------
global calculationflag;
if calcultionflag ==0
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.result1, 'String', f);
calculationflag = calculationflag+1;
else if calculationflag ==1
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.result2, 'String', f);
calculationflag = calculationflag+1;
else if calculationflag ==2
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.result3, 'String', f);
calculationflag=0;
end
--------------------------------------
Thanks!
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 11월 6일
What error do you observe, and on what line?
sha
sha 2012년 11월 6일
i have edited the command. the 'elseif' need to be in one word. However. after doing so, it didnt work. there is no error at all. but no calculation has been done.
Any suggestion? thanks fr the reply!

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 11월 6일
편집: Walter Roberson 2012년 11월 6일
persistent calculationflag
if isempty(calculationflg); calculationflag = 0; end
p = str2num(get (handles.load, 'String'));
d = str2num(get (handles.diameter, 'String'));
n = str2num(get (handles.fringe, 'String'));
f = ( (8 * p ) / (pi * d * n));
fstring = num2str(f);
switch calculationflag
case 0: set(handles.result1, 'String', fstring);
case 1: set(handles.result2, 'String', fstring);
case 2: set(handles.result3, 'String', fstring);
end
calculationflag = mod(calculationflag+1, 3);
  댓글 수: 3
José-Luis
José-Luis 2012년 11월 6일
calculationfl a g
sha
sha 2012년 11월 6일
my bad! after doing so, i could only manage to do 1 time. and has an error after clicking the button fr 2nd times!
this are the error:
---------------------------------
??? Error while evaluating uicontrol Callback
??? One or more output arguments not assigned during call to "set".
Error in ==> New>calculationPushbutton_Callback at 504 case 0: set(handles.result1, 'String', fstring);
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
---------------------------------------

댓글을 달려면 로그인하십시오.

카테고리

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