function_handle in randomAffine3d - invalid type for 'Shear': expected numeric but function_handle instead.

1 回表示 (過去 30 日間)
drummer
drummer 2020 年 10 月 22 日
コメント済み: drummer 2020 年 10 月 23 日
Hi all,
I'm stuck with an issue that it is driving me crazy, because I think I covered all approaches here.
I'm getting the error:
Error using randomAffine3d>iParseInputs (line209)
The value of 'Shear' is invalid. Expected Shear to be one of these types:
numeric
Instead its type was function_handle.
Error in randomAffine3d (line 114)
args = iParseInputs(varargin{:});
So I was checking my approaches
tform2 = randomAffine3d('Shear', [-4 4]) % it works
tform2.T
tform3 = randomAffine3d('Shear', @selectShear) % That's where I'm getting the error.
tform3.T
My function handle is
function numericShear = selectShear
p = 3;
shearMin = -4;
shearMax = 4;
n = 1000;
numericShear = shearMin + (shearMax - shearMin)*sum(rand(n, p, 'gpuArray'), 2)/p;
numericShear = gather(numericShear(randi(numel(numericShear))));
end
I even made
numericShear = 5; % and commented the construction for numericShear above. But that's not the problem also.
I have other functions for 'Scale' and 'Rotation' as well (and exactly the same, only changing variables obviously), and they work great.
What could be the problem?
  2 件のコメント
Raymond Norris
Raymond Norris 2020 年 10 月 22 日
Hi,
This isn't my area, but looking at randomAffine3d, notice the difference between how the input args are validated for each:
function TF = validateScale(val)
if ~isa(val,'function_handle')
iValidateNumericRange('Shear',val,'positive');
end
TF = true;
end
function TF = validateShear(val)
iValidateNumericRange('Shear',val,'<',90,'>',-90);
TF = true;
end
Scale allows for a function handle. If it's not than it follows the same requirement for Shear, which requires specifically a numeric value (within a range).
Raymond
drummer
drummer 2020 年 10 月 23 日
Hi Raymond, thank you.
Indeed Scale allows for a function handle. So the other parameters for geometric transformation, as you might have seen in the documentation.
I have made function handles for Scale, Rotation, Shear and Translation (for x, y and z).
You also may have noticed that I can insert Name-Value pair arguments for each one of them. And the value, for all of them is a vector to set the range.
Why I want to use function handle? Because by using the Name-Value pair arguments, the random values in the range set by the vector are chosen through a uniform distribution probability, while I want to pick the random values by a Gaussian distribution, and that's the purpose of my function handle - to return a numeric value between the interval I set previously within the function handle following such probability.
Therefore, all my function handles are returning a numeric type. But for 'Shear' I'm having this issue of function_handle type. And they are 'the freakin' same!!
Also, I think that shearMin and shearMax are validated as inputs, according to the checks in the input arg you mentioned, right?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing Fundamentals についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by