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: Sat, 29 Sep 2012 18:18:04 -0400

On Sat, Sep 29, 2012 at 4:53 PM, Dario <address@hidden> 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
address@hidden
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

reply via email to

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