Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Booleans and Matrices

Subject: Booleans and Matrices

From: Margaret

Date: 7 Mar, 2012 01:21:12

Message: 1 of 3

I have to design a program that verify's whether a square matrix meets part of the requirements of a Sudoku matrix. Using Boolean operators I have to verify that the sums of the rows and colums are equal. I have been able to program this into a function but the answer still comes out verifying each element inside the matrix and not the matrix as a whole. This is what I have so far:

function x = isHSudoku(X)
% This function checks to see if a vector meets the requirements of a half
% sudoku matrix in which all colums and rows add up to the same value.
x=((sum(X))==(sum(X')));

when using this function the answer looks like this:


ans =
     0 1 0

I need is to simply answer 1 or 0. How do I get MATLAB to register the matrices as a whole and not based on their parts?

Subject: Booleans and Matrices

From: dpb

Date: 7 Mar, 2012 01:37:47

Message: 2 of 3

On 3/6/2012 7:21 PM, Margaret wrote:
...

> when using this function the answer looks like this:
>
>
> ans =
> 0 1 0
>
> I need is to simply answer 1 or 0. How do I get MATLAB to register the
> matrices as a whole and not based on their parts?

doc any
doc all

--

Subject: Booleans and Matrices

From: Roger Stafford

Date: 7 Mar, 2012 02:50:24

Message: 3 of 3

"Margaret " <margaretviola@wustl.edu> wrote in message <jj6d68$4j0$1@newscl01ah.mathworks.com>...
> I have to design a program that verify's whether a square matrix meets part of the requirements of a Sudoku matrix. Using Boolean operators I have to verify that the sums of the rows and colums are equal.
- - - - - - - -
  Strictly speaking it is not sufficient to show that the row and column sums are all equal. It is possible to have a row with the proper sum be, say, 4+6+8+1+2+9+2+8+5 = 45 and yet not be a valid Sudoku row. (Hint: you will find the 'sort' function very useful in making a valid comparison.)

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us