Error in calculation code
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!