[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

find() and setting matrix elements to 1

From: Victor Semanic
Subject: find() and setting matrix elements to 1
Date: Tue, 8 Oct 2013 09:05:47 -0700 (PDT)

Hello all: Quick problem that I am sure has an elegant solution instead of 
using loops.

I have a 5x6 matrix of random numbers.
octave> C = rand(5,6);

I want to change to 1 all the elements in the matrix that are <= 0.50.
octave> [i j] = find(C <= 0.50);

The above gives me the indexes of rows in i and columns in j where the
elements are <= 0.50.  I want to now set these elements to 1.

I try the following:
octave> C(i,j) = 1.0;

But that simply turns the C matrix into a matrix with all 1's.

I can loop through the indexes in i and j and set the elements of C to 1, 
I want to avoid looping and let Octave do all the hard work.

Any ideas how I accomplish this?

Thanks so much for your time.  I did look at the boards but was not able to 
find a
question matching this one.  Hence I reach out on the list.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]