필터 지우기
필터 지우기

arg max data type

조회 수: 1 (최근 30일)
Mats
Mats 2022년 5월 13일
댓글: Steven Lord 2022년 5월 13일
Take the following example
x = single(-(-2:2).^2);
[xm,ix]=max(x);
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char ix 1x1 8 double x 1x5 20 single xm 1x1 4 single
I think it strange that variable ix is of type double, and not integer, which would be the most logical alternative.
Anyway, I am using this kind of line for a code generation case, where double data type is banned.
Is there any way I can force max function to return an integer value for argmax (variable ix in code above)?
  댓글 수: 1
Steven Lord
Steven Lord 2022년 5월 13일
I think it strange that variable ix is of type double, and not integer, which would be the most logical alternative.
I suspect that the two-output form of max predates the introduction of the integer data types to MATLAB.

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

채택된 답변

Matt J
Matt J 2022년 5월 13일
No, but can't you just cast it to an integer type post-facto? E.g.,
ix=cast(ix,'uint32');
  댓글 수: 1
Mats
Mats 2022년 5월 13일
Hi. I did not even try this trick because I though that you cannot change the datatype of a variable when using code generation (which is generally true). However, becuase code generator is quite smart your suggestion works nicely.
Thank you Matt!

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

추가 답변 (0개)

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by