Whats wrong with my code?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!