フィルターのクリア

Whats wrong with my code?

3 ビュー (過去 30 日間)
Ju
Ju 2012 年 2 月 24 日
hello all, i have a problem.
i have 3 edit box ---> c_edit, p_edit, and result.
i have 1 pushbutton.
my code for pushbutton callback is:
ciph = str2num(get(handles.c_edit,'String'));
priv = str2num(get(handles.p_edit,'String'));
[line ciphSize] = size(ciph);
[line privSize] = size(priv);
global bin
for i=1:1:ciphSize
for j = privSize:1
if ciph(i) >= priv(j)
bin(j) = 1;
ciph(i) = ciph(i) - priv(j);
else
bin(j) = 0;
end
end
set(handles.result,'String',num2str(bin));
for example :
ciph = 6 8 2
priv = 2 6
so bin= 1 0 1 1 0 1
but the result edit box show nothing. Can anyone tell me whats wrong with this?
thanks a lot.

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 24 日
If c_edit or p_edit are not convertible to number, then the size could come out 0, causing you to not loop at all.
If they are convertible to number, then if privSize is greater than 1, your loop over j would have a colon operator with a higher end value than start value, which is defined to mean no looping.
If you want to loop backwards you need a negative increment, such as
for j = privSize : -1 : 1
  1 件のコメント
Ju
Ju 2012 年 2 月 26 日
thank you very much, it works now..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by