How can i find the position of a number in a cell consisting of arrays/matrices with different sizes
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
the cyclist
2013 年 12 月 28 日
編集済み: the cyclist
2013 年 12 月 28 日
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.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!