Whats wrong with my code?
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 24 Feb 2012
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
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!