How to convert a matrix of double to int?

조회 수: 1,122 (최근 30일)
Emilie Mussard
Emilie Mussard 2013년 12월 5일
댓글: Macro 2024년 1월 2일
I need to convert my matrix [648x2400 double] into integers value to use a mRMR function, but I do not know how to do that. I have tried to convert by uint8(matrix) or int8(matrix) but it does not give integers... And I always have this note: "Undefined function 'mrmr_mid_d' for input arguments of type 'int8' " (or double, or uint, and so on) can someone help me? thank you
  댓글 수: 1
Nguyen Phuong
Nguyen Phuong 2019년 9월 11일
img_d = double(img);
imshow(img_d/255);

댓글을 달려면 로그인하십시오.

채택된 답변

Wayne King
Wayne King 2013년 12월 5일
편집: Wayne King 2013년 12월 5일
I'm not sure what you are saying. Do you mean that:
X = 10+randn(16,16);
X = uint8(X);
Does not result in integers for the output in X?
The error message you report ("Undefined function 'mrmr_mid_d' for input arguments of type 'int8' ") just sounds like MATLAB cannot recognize the function, mrmr_mid_d.m.
You need to add the folder containing that function to the MATLAB path. You can launch
>>pathtool
to add that folder.
  댓글 수: 1
Emilie Mussard
Emilie Mussard 2013년 12월 5일
Thank you, I hadn't thought of the path problem and I focused on a wrong problem!

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Kelly Kearney
Kelly Kearney 2013년 12월 5일
It's possible that mrmr_mid_d.m isn't on your path; the other possibility is that it doesn't actually accept integer data types as input, but integer values stored as double arrays. In this case, you need to round your data in some manner (see round, ceil, floor, fix, etc)
x = rand(10)*10;
x = round(x);
mrmr_mid_d(x); % or whatever the syntax is...

MathWorks Support Team
MathWorks Support Team 2018년 11월 27일
To convert an array of type “double” to an integer type, you can use a function such as “int64”, which converts the input to a 64-bit integer. For example, consider the following:
x_double = [1 2 3];
x_int = int64(x)
For more information on integer types and functions, see https://www.mathworks.com/help/matlab/matlab_prog/integers.html
  댓글 수: 1
Macro
Macro 2024년 1월 2일
Thank you for sharing. Great information! Converting a double array to an integer type is a common task in programming, and using the "int64" function for a 64-bit integer conversion is a smart approach. Your example is helpful for me.

댓글을 달려면 로그인하십시오.


sixwwwwww
sixwwwwww 2013년 12월 5일
you can do it as follow:
a = randi(100, 4);
a = int64(a);
see following link for more information about integer data types:
  댓글 수: 2
Emilie Mussard
Emilie Mussard 2013년 12월 5일
Yes, it is what I have made. I thought that int64 (or int32, ...) was not the same type as int and so my function was not running on it, apparently I misunderstood and the problem is maybe in another place... Thank you for your prompt answer anyway!
Munawara Munia
Munawara Munia 2016년 4월 26일
Hi Emilie, I am facing the same problem. I ama also trying to use mRMR and getting the same errors. Could you kindly tell me what was the issues with your code and how you solved it..?? Badly need a solution about it. Thanks in advance. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by