user36729
user36729

Reputation: 575

Convert double matrix to integer matrix in Matlab

I built two binary matrices in R then loaded them to MATLAB. I want to do feature selection by the use of this function:

[steps,sel_flag,rel,red,cond_red] = select_features(BinaryMat1,BinaryMat2, 'degree', 2);

Two binary matrices are in double format, but I got this error:

Undefined function select_features for input arguments of type double.

What should I do to convert these two matrices to integer in Matlab? I have tried uint8, int32 and int64 but I got the same error each time.

Upvotes: 0

Views: 1108

Answers (1)

rayryeng
rayryeng

Reputation: 104484

Simply convert each matrix to logical. That can be done by casting them before calling the function:

BinaryMat1 = logical(BinaryMat1);
BinaryMat2 = logical(BinaryMat2);
[steps,sel_flag,rel,red,cond_red] = select_features(BinaryMat1,BinaryMat2, 'degree', 2);

Minor Note

You also may be getting that error because MATLAB can't find that function to run. Make sure you have this function on your computer before running the code. The function you referenced is not part of MATLAB's native environment, but by doing a simple Google search, I found this:

http://www.mathworks.com/matlabcentral/fileexchange/26981-feature-selection-based-on-interaction-information/content//select_features/select_features.m

Upon looking at the source, it doesn't look like the inputs are just exclusively for binary matrices. It looks like they can be any matrices so long as they represent integral types, so integer, unsigned integer could also have worked, but I highly suspect that you didn't download the toolbox correctly, or assumed that this toolbox was part of MATLAB's native libraries.

The full toolbox can be found here: http://www.mathworks.com/matlabcentral/fileexchange/submissions/26981/v/1/download/zip

This is part of a custom toolbox written by an individual independent of MathWorks, so make sure you download this toolbox, put it somewhere that is accessible, and then run the code again.

Download the toolbox, extract the contents from the archive (.zip) file, then add this directory to MATLAB's path. You can do this by either going to File->Set Path and adding this directory to MATLAB's path, or doing this in the command prompt by:

path(path,genpath('/path/to/toolbox/dir'));

Upvotes: 1

Related Questions