Feb 28

Posted by abiao at 11:52 | Code » Matlab | Comments(1) | Reads(11768)
Sudoku is one of my favorite small games I often have fun with, I save one copy at my gphone and play it whenever I want to take a rest. (most of us may have a wrong impression that Sudoku originated in Japan, no, in America.)

I happened to find Cleve Moler solved Sudoku using recursive backtracking method and the speed is fast, the minor error is it doesn't report an error when the initial 9*9 matrix you give violates Sudoku rules (you can test it later, the code starts to run and returns a result even you give repetitive numbers along a same row or column). Since building a GUI in matlab isn't easy, I choose to build a Sudoku spreadsheet using Matlab Excel link for an example.

Once you install Excel Link module and turn it on, you will notice the short-cuts on the excel menu bar looking like

intuitively, those buttons stand for "start matlab", "send data to matlab", "retrieve data from matlab", and "execute the matlab command", respectively.

For my case, I first download the Sudoku M code at http://www.mathworks.co.uk/company/newsletters/news_notes/2009/clevescorner.html?s_cid=ACD0210ukTA2&s_v1=8728847_1-BR7DSN, then open an excel file, write down a 9*9 matrix "X"

then define a zone to fetch the calculation result, which should also be 9*9

finally do steps:
<- put data to matlab, MLPutmatrix("X",X)
<- solve the problem in matlab, MLEvalString("X=sudoku(X)")
<- get results from matlab, MLGetMatrix("X","NewX")

result is then retrieved immediately to Sudoku Spreadsheet from matlab

Straightforward to run your Matlab function in excel, isn't it? alternatively you can use Matlab builder for excel.

Tags: ,
The information is top quality, you may see quite a few exclusive things that can't be found on other blogs, really versatile but still very specific!
the sims mobile cheats
Pages: 1/1 1
 Add a comment Emots Enable HTML Enable UBB Enable Emots Hidden Remember Nickname   Password   Optional Site URI   Email   [Register]