How can i find the position of a number in a cell consisting of arrays/matrices with different sizes

1 view (last 30 days)
Edited question:
My main cell:
Columns 1 through 5
[1x4 double] [1x3 double] [1x3 double] [1x5 double] [1x3 double]
[1x4 double] [ 8] [1x4 double] [1x6 double] [1x5 double]
[ 5] [ 4] [ 3] [ 2] [ 6]
[1x3 double] [1x3 double] [ 8] [1x2 double] [ 1]
[ 2] [1x4 double] [1x4 double] [1x5 double] [ 6]
[1x2 double] [1x3 double] [ 7] [1x2 double] [ 9]
[1x2 double] [ 3] [ 6] [1x4 double] [ 2]
[1x2 double] [1x3 double] [1x3 double] [1x6 double] [1x4 double]
[ 9] [ 8] [ 4] [1x3 double] [1x3 double]
Columns 6 through 9
[1x4 double] [ 4] [ 5] [ 2]
[1x5 double] [1x3 double] [1x2 double] [1x3 double]
[1x2 double] [ 1] [ 7] [1x2 double]
[1x3 double] [ 2] [1x3 double] [1x4 double]
[1x5 double] [1x5 double] [1x4 double] [ 1]
[1x3 double] [ 4] [1x2 double] [1x3 double]
[ 4] [ 5] [1x3 double] [1x2 double]
[1x6 double] [1x6 double] [ 1] [1x7 double]
[1x3 double] [1x3 double] [1x2 double] [1x2 double]
Each row represents one of the 9 main boxes inn a sudoku board, http://i.msdn.microsoft.com/dynimg/IC83657.gif:
the operation Cell{2,:} gives me to possible values for each small window in main box 2:
ans = 1 6 7 9
ans = 8
ans = 2 6 7 9
ans = 1 3 4 5 7 9
ans = 3 4 5 7 9
ans = 3 4 5 7 9
ans = 3 6 9
ans = 3 9
ans = 3 6 9
the first row being position (1,1) in main box 2, and position 1,4 in the total board. the fourth row being position (2,1) in main box 2, and position 2,4 in the total board.
Now having explained the case (maybe a bit too much), my question is.
How can i find the position of the number 2 (already knowing only exists one place, and of course not knowing its position) in Cell{2,:}, and also knowing the first index, being 2 from Cell{2,:}?
  1 Comment
Jan
Jan on 28 Dec 2013
Edited: Jan on 28 Dec 2013
Why is "(2,3)" a correct answer for searching a 2? Does the index 2 mean, that you search in the 2nd row of the cell? What do the other not shown elements of the cell contain?

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 28 Dec 2013
Edited: the cyclist on 28 Dec 2013
Here is one way:
C = {[1 6 7 9], [1 6 7 9], [1 6 7 9];
[8], [8], [2 6 7 9]};
[ii,jj] = find(cell2mat(cellfun(@(x) any(ismember(x,2)),C,'UniformOutput',false)))
If you have more than one cell location with a 2 in it, ii will have all the row coordinates, and jj will have all the column coordinates.
There is a lot buried in that one line of code, including some assumptions about how you want this to generalize.

More Answers (0)

Categories

Find more on Sudoku 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!