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:
writing functions

Subject: writing functions

From: Isabelle

Date: 10 Sep, 2013 02:17:07

Message: 1 of 2

im writing a 'winning' command on matlab for knots and crosses, how do i get matlab to:

take the sum of all the rows and columns and check if either of them equal to 3 or -3?
in the simplest way

Subject: writing functions

From: Nasser M. Abbasi

Date: 10 Sep, 2013 02:47:34

Message: 2 of 2

On 9/9/2013 9:17 PM, Isabelle wrote:
> im writing a 'winning' command on matlab for knots and crosses, how do i get matlab to:
>
> take the sum of all the rows and columns and check if either of them equal to 3 or -3?
> in the simplest way
>


EDU>> winning=randi([-2 2],4,4)
      0 1 -2 2
     -2 1 -1 0
      1 1 2 2
     -1 0 -2 -2

EDU>> sum(winning,1)==3
      0 1 0 0

EDU>> sum(winning,2)==3
      0
      0
      0
      0

So only the second column sums to 3. No rows sum to 3.

--Nasser

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