Info

此问题已关闭。 请重新打开它进行编辑或回答。

could anyone help me to run the code without error.

1 次查看(过去 30 天)
A=[ 1 2 3 4 5 31 36 71 72;
11 12 13 14 15 32 37 73 74;
6 7 8 9 10 33 38 75 76;
21 22 23 24 25 34 39 77 78;
26 27 28 29 30 35 40 79 80;
41 42 43 44 45 46 47 81 82;
48 49 50 51 52 53 54 83 84;
85 86 87 88 89 90 91 92 93;
94 95 96 97 98 99 16 17 18]
B=[0 0 61 0 0 0 0 0 0;
65 0 0 0 0 0 0 0 0;
0 63 0 0 0 0 0 0 0;
0 0 0 62 0 0 0 0 0;
0 0 0 0 64 0 0 0 0;
0 0 0 0 0 0 67 0 0;
0 0 0 0 0 68 0 0 0;
0 0 0 0 0 0 0 66 0;
0 0 0 0 0 0 0 0 69]
a=1:9
for R=2:4
for N=2:4
c=randsample(a,N)
C=B(c,:)
non_0=sum(C)
Z =repmat(non_0,R,1)
E=C
E(Z & C ==0)= A(Z & C ==0)
[~,idx]=find(ismember(a,c))
if N==4
else
a(idx)=[]
end
end
end
  1 个评论
Rik
Rik 2018-1-6
Sure. First reply to the questions you got on the other threads.

回答(1 个)

Walter Roberson
Walter Roberson 2018-1-6
No, it appears that we cannot do that. We have told you on a number of occasions that it is necessary that you document the purpose of the algorithm and the intent of the individual steps. It is not possible for us to tell you how to fix code whose purpose is not known.
We could tell you what is triggering the problem, but the fix for the problem involves changing the reference to R, and once the reference to R is removed then the purpose for having an R loop becomes unclear. This suggest that you need to redesign the code to meet whatever purpose it is that you have in mind for it.
Documentation and comments helps other people who read the code, but it also helps you design the code. At each step you should have a clear understanding of how large each variable is, which should make conflicts in the size of the variables obvious, and when you debug (we have pointed you to the debugger documentation more than once) you can test the size of your variables against your comments about the size and use the information about the actual size to figure out which variable is the wrong size and move backwards from there to figure out how it got to be the wrong size.
There is a technique in program design in which at each independent block, you document "pre-conditions" and "post-conditions" -- the list of things that are assumed to be true before the code together with the list of changes and new assumptions. Some people only document those on the function level -- but they also write a lot of small functions. When you write larger blocks of code then it can help a lot to put in those comments at each significant code block.
You need to stop flailing around and start writing down what your code and each section of the code needs to do, which gives you hints about how to write the code, and gives you a lot of information to help you (and other people) debug the code.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by