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:
Matrices

Subject: Matrices

From: Rae Santiago

Date: 20 Mar, 2011 06:12:04

Message: 1 of 2

I am working on a greedy algorithm.
I so far have an nxn matrix M and nx1 matrix with ones.
Example: M= [0 1 2; 2 0 3; 4 2 0]; and I= [1;1;1].
Eventually matrix M will have more and more zeros.
Say now I have the modified M = [0 0 0; 0 0 3; 0 2 0].
How would I write in MATLAB that if row 1 and column 1 are all zeros
then I(1) = 0.

It's for my dissertation :) thank you!

Subject: Matrices

From: Nasser M. Abbasi

Date: 20 Mar, 2011 06:25:46

Message: 2 of 2

On 3/19/2011 11:12 PM, Rae Santiago wrote:
> I am working on a greedy algorithm.
> I so far have an nxn matrix M and nx1 matrix with ones.
> Example: M= [0 1 2; 2 0 3; 4 2 0]; and I= [1;1;1].
> Eventually matrix M will have more and more zeros.
> Say now I have the modified M = [0 0 0; 0 0 3; 0 2 0].
> How would I write in MATLAB that if row 1 and column 1 are all zeros
> then I(1) = 0.
>
> It's for my dissertation :) thank you!

-----------------------
M = [0 0 0; 0 0 3; 0 2 0];
I=rand(3,1)
I =
     0.1112
     0.7803
     0.3897

I(ismember(M,zeros(size(M,1)),'rows'))=0

I =
          0
     0.7803
     0.3897
------------

--Nasser

Tags for this Thread

No tags are associated with 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