help-octave
[Top][All Lists]
Advanced

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

Re: How to generate logical column vector from matrix rows?


From: James Sherman Jr.
Subject: Re: How to generate logical column vector from matrix rows?
Date: Sun, 30 Sep 2012 08:41:01 -0400

On Sun, Sep 30, 2012 at 7:12 AM, Dario <address@hidden> wrote:
James Sherman wrote
> On Sat, Sep 29, 2012 at 4:53 PM, Dario <

> bero_leadstar@

> > wrote:
>
>> bpabbott wrote
>> > On Sep 28, 2012, at 2:00 PM, Dario wrote:
>> >
>> >> Hey guys,
>> >> I'm a new Octave user.
>> >> I have one question for you.
>> >> Matrix is formed of values -1, 0, and 1.
>> >> If I have -1 and 1 in one row of the matrix I need to get "true" for
>> this
>> >> row, otherwise I need to get "false".
>> >> I need to loop through all rows of the matrix and get a logical column
>> >> vector assigned to the matrix.
>> >> Please help me! :-)
>> >>
>> >> P.S. sorry for mistakes, I'm new in English
>> >
>> > For "A" being your matrix, does this work for you?
>> >
>> >       all (repmat ([-1, 1], size (A, 1), 1) == A, 2)
>> >
>> > Ben
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>>
>> > Help-octave@
>>
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>>
>> thanks for a try, but i keep getting this error message
>> error: mx_el_eq: nonconformant arguments (op1 is 10x2, op2 is 10x5)
>> error: evaluating argument list element number 1
>>
>> My matrix A is 10x5 matrix filled with values of -1, 0, 1.
>> The row is true if a combination of values -1 and 1 is appeared in any
>> row
>> of the matrix.
>>
>>
>>
>> --
>> View this message in context:
>> http://octave.1599824.n4.nabble.com/How-to-generate-logical-column-vector-from-matrix-rows-tp4644771p4644777.html
>> Sent from the Octave - General mailing list archive at Nabble.com.
>> _______________________________________________
>> Help-octave mailing list
>>

> Help-octave@

>> https://mailman.cae.wisc.edu/listinfo/help-octave
>>
>
> Hello,
>
> If I understand your question correctly, you want "true" if there are no
> 0's in a row, and false if there is at least one 0 (i.e. not zero 0s).
>
> I think you can do this in one line, where A is your original matrix with
> -1, 0, and 1:
> row_truth = all(A' ~= 0)';
>
> Which should give you a column vector with 1 if there is no zeros its
> corresponding row, and 0 otherwise.
>
> Hope this helps.
>
> James Sherman
>
> _______________________________________________
> Help-octave mailing list

> Help-octave@

> https://mailman.cae.wisc.edu/listinfo/help-octave

Thank you James, this works fine, but it's not what I need.
I think it would be best if I write you what I need to get.
So, my result should look like that:

Matrix A:                                     Logical column vector:

row 1: 0 0 1 1 1                           0
row 2: 0 -1 0 1 1                          1
row 3: 0 -1 -1 0 -1                        0
row 4: 0 -1 -1 1 0                         1
row 5: 1 0 0 -1 -1                         1
row 6: 1 0 1 0 1                           0
row 7: 1 0 1 -1 0                          1
row 8: 1 -1 0 0 -1                         1
row 9: 1 -1 0 1 0                          1
row 10: -1 1 -1 0 0                       1



--
View this message in context: http://octave.1599824.n4.nabble.com/How-to-generate-logical-column-vector-from-matrix-rows-tp4644771p4644792.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave

Ah, ok.  Sorry for the misunderstanding.  Here's a second shot at it:

row_truth = (any(A'==1)&any(A'==-1))';

This will return true if there is at least one 1 and at least one -1 in the row (doesn't care about zeros).

reply via email to

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