Utilizing sqrt and square, "Check for incorrect argument data type or missing argument in call to function 'sqrt'"

18 ビュー (過去 30 日間)
Casey Park
Casey Park 2021 年 9 月 30 日
編集済み: Rik 2021 年 9 月 30 日
I am currently trying to create an expression
where Ix, and Iy are 100x100 uint8 matrixes
X = sqrt((Ix^2)+(Iy^2))
However I get "Check for incorrect argument data type or missing argument in call to function 'sqrt'"
I am wondering what is wrong here, additionally should I be using element power ".^" instead of "^"?
  2 件のコメント
VBBV
VBBV 2021 年 9 月 30 日
編集済み: VBBV 2021 年 9 月 30 日
you can check, if Ix and Iy have been used elsewhere in your function call /scripts for different purpose
Stephen23
Stephen23 2021 年 9 月 30 日
The SQRT function is only defined for floating point types SINGLE and DOUBLE, not for integer types:

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2021 年 9 月 30 日
編集済み: Rik 2021 年 9 月 30 日
As Stephen mentioned, the sqrt function expects either single or double. So you will have to convert it to either of those data types.
Additionally, you probably want to use .^ as that would make the square element-wise. If you don't, it makes more sense you want sqrtm instead.
X = sqrt(double( (Ix.^2)+(Iy.^2) ));
You could also consider hypot to do this computation.
help hypot
HYPOT Robust computation of the square root of the sum of squares C = HYPOT(A,B) returns SQRT(ABS(A).^2+ABS(B).^2) carefully computed to avoid underflow and overflow. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are either the same or one of them is 1. Example: format short e a = 3*[1e300 1e-300] b = 4*[1e300 1e-300] c1 = sqrt(a.^2 + b.^2) c2 = hypot(a,b) x = 1.271161e308 y = hypot(x,x) Class support for inputs A, B: float: double, single See also ABS, NORM, SQRT. Documentation for hypot doc hypot Other functions named hypot codistributed/hypot gpuArray/hypot sym/hypot

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by