How to stop my "if" statement in a "for" loop
古いコメントを表示
Hi, with your help i was able to program this code.
clc
M = dec2bin(0:2^15-1, 15);
%A=zeros(5);
j=1;
for i=1:2^15
A(1,2:6,i) =[str2num(M(i,1)),str2num(M(i,2)),str2num(M(i,3)),str2num(M(i,4)),str2num(M(i,5))];
A(2,3:6,i)=[str2num(M(i,6)),str2num(M(i,7)),str2num(M(i,8)),str2num(M(i,9))];
A(3,4:6,i)=[str2num(M(i,10)),str2num(M(i,11)),str2num(M(i,12))];
A(4,5:6,i)=[str2num(M(i,13)),str2num(M(i,14))];
A(5,6,i)=[str2num(M(i,15))];
if (A(1,2,i)==1) & (A(1,3,i)==1) & (A(1,4,i)==1) & (A(1,5,i)==1) & (A(2,3,i)==1) & (A(2,6,i)==1)
B(:,:,j)=A(:,:,i)
j=j+1;
end
end
For some reason it doesn't stop after creating all the B(:,:,j) and starts with j=1 again. After creating B(:,:;501) he starts with B(:,:,1) again.
PS: If i kill the the program after the program already repeated to create the B(:,:,j) at some point, i can see that it didn't create the last few allowed matrices. Whats the reason for that?
1 件のコメント
Jan
2013 年 7 月 3 日
Did you see our suggestions if your other questions? The code can be compressed significantly and the result would be tremendously faster and nicer. It discourages me to post further asnwers, when I see that the former ones are ignored.
You can use the debugger to find the problems locally: Set a breakpoint in a line, which reveals the problems.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および 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!