To determine if a variable has binary in MATLAB you can use the isbinary
function. This function returns true if all elements of the input argument are logical 0 or 1, and false otherwise. Here is an example:
main.m148 chars6 lines
In this example, isbinary_x
returns true because all elements of x
are either 0 or 1, whereas isbinary_y
returns false because y
contains non-binary elements (2, 3, and 4).
gistlibby LogSnag