This question is closed. Reopen it to edit or answer.

why the answer is not showing any matrix after applying IF condition?

1 view (last 30 days)
can anybody please check this code. After running this, I cannot find any cell named allCells_array 1st it generates combinations of 3 cells and 7 machines using this part
CELL = zeros(no_of_cells^no_of_machines,no_of_machines);
t = 0;
for l = 0:(no_of_cells^no_of_machines)-1
s = dec2base(l,no_of_cells,no_of_machines);
if length(unique(s))==no_of_cells
t = t+1;
CELL(t,:) = s-'0'+1;
CELL = CELL(1:t,:);
the transform the above arrays into matrices of binary digits
for m=1:r1
Z = zeros(R(end),max(combination_array{m}));
Z(sub2ind(size(Z),R,combination_array{m})) = 1;
*here I want that the obtained Z must have all column sums >= 2*
if all(X>=2)
but the result is not showing any allCells_array why is this so?
  1 Comment
Adam on 25 Jan 2017
Edited: Adam on 25 Jan 2017
Have you used the debugger? It should be trivial to find the reason why if you just put a breakpoint in. Certainly a lot easier than someone trying to just scan over the code and work out what is what and where.
Put a breakpoint at the start of the 'if' line and take a look at X.

Answers (1)

dpb on 25 Jan 2017
Edited: dpb on 27 Jan 2017
"... I cannot find any cell named allCells_array"
X=sum(Z,2); % will be column vector of sums
if all(X>=2) % will be T IFF every row in X is >2 which doesn't happen
Think you're looking for
probably unless you actually want Z for those rows for which X>1 rather than the sums.
Follow-up to comment earlier on the building of the Z I thought, it's clear this can never work as you've written it to return anything as in
Z(sub2ind(size(Z),R,combination_array{m})) = 1;
For the case you have, the index expression reduces to
which asks for a set of indices for each of 7 rows with only a single element to go with each from the array. Hence, there can NEVER be a case where the sum of the rows is >1 as there is just one column associated with each row in the array that is going to be set.
As noted there, I still don't follow just what your intent is here precisely; I kinda' grasp it's trying to split up combinations of N things amongst M pools, but don't have the time to try to divine the intent from non-working code with no comments.
But the above is why you don't get any results in the end...and never will with the logic as is.
dpb on 25 Jan 2017
Edited: dpb on 25 Jan 2017
But, I instrumented your code with a pinpoint diagnostic of
to get a location to look at what's going on and guess what!!?? No locations showed up. Your logic in building Z doesn't appear to be what you're expecting it to be. I'm not absolutely sure what this is trying to do without more time than have to spend trying to figure it out, but look carefully out how you're building Z; doesn't look to me as though there's ever more than one bit per any line in the array as is...

Community Treasure Hunt

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

Start Hunting!

Translated by