# randomAffine3d() claim to take function handle for shear, but parser fails it

1 view (last 30 days)
Commented: Mads on 24 Mar 2023
According to the doc of randomAffine3d:
Shear Range of shear
[0 0] (default) | 2-element numeric vector | function handle
...
A function handle. The function must accept no input arguments and return the shear angle as a numeric scalar. Use a function handle to pick a shear angle from a disjoint interval or using a nonuniform probability distribution.
When using this function e.g.
function A = selectShear1
A = -(rand(1,1)*5+5);
end
the validator (below) returns with this error message:
'The value of 'Shear' is invalid. Expected Shear to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
which seems to be alright given:
function TF = validateShear(val)
iValidateNumericRange('Shear',val,'<',90,'>',-90);
TF = true;
end
That it after all doesn't take function handles...
Steven Lord on 24 Mar 2023
Can you show us the code you've written to call randomAffine3d using this function handle?

for ro = [0,-1,1]
if ro == -1
Rot = @selectRotation1;
elseif ro == 0
Rot = [0,0];
elseif ro == 1
Rot = @selectRotation2;
end
for sh = [0,-1,1]
if sh == -1
She = [-10,-5];%%@selectShear1;
elseif sh == 0
She = [0,0];
elseif sh == 1
She = [5,10];%@selectShear2;
end
for sc = [0,-1,1]
if sc == -1
Sca = @selectScale1;
elseif sc == 0
Sca = [1,1];
elseif sc == 1
Sca = @selectScale2;
end
for tl = [0,-1,1]
if tl == -1
Trax = -[Tr2,Tr1];
Tray = -[Tr2,Tr1];
Traz = -[Tr2,Tr1];
elseif tl == 0
Trax = [0,0];
Tray = [0,0];
Traz = [0,0];
elseif tl == 1
Trax = [Tr1,Tr2];
Tray = [Tr1,Tr2];
Traz = [Tr1,Tr2];
end
for zr = 0:1
tform = randomAffine3d(Rotation=Rot,Shear=She,Scale=Sca,XTranslation=Trax,YTranslation=Tray,ZTranslation=Traz);
end
end
end
end
end
function [rotationAxis,theta] = selectRotation1
theta = rand(1,1) * 10+5;
rotationAxis = [1,0,0]';
theta1 = rand(1,1) * 10;
theta2 = rand(1,1) * 10;
% Rz = [cosd(theta2),-sind(theta2),0;sind(theta2),cosd(theta2),0;0,0,1];
Rx = [1,0,0;0,cosd(theta2),-sind(theta2);0,sind(theta2),cosd(theta2)];
Ry = [cosd(theta1),0,sind(theta1);0,1,0;-sind(theta1),0,cosd(theta1)];
rotationAxis = Rx*Ry*rotationAxis;
rotationAxis = rotationAxis(:)';
end
function [rotationAxis,theta] = selectRotation2
theta = rand(1,1) * 10+5;
theta = -theta;
rotationAxis = [1,0,0]';
theta1 = rand(1,1) * 10;
theta2 = rand(1,1) * 10;
% Rz = [cosd(theta2),-sind(theta2),0;sind(theta2),cosd(theta2),0;0,0,1];
Rx = [1,0,0;0,cosd(theta2),-sind(theta2);0,sind(theta2),cosd(theta2)];
Ry = [cosd(theta1),0,sind(theta1);0,1,0;-sind(theta1),0,cosd(theta1)];
rotationAxis = Rx*Ry*rotationAxis;
rotationAxis = rotationAxis(:)';
end
function A = selectShear1
A = -(rand(1,1)*5+5);
end
function A = selectShear2
A = (rand(1,1)*5+5);
end
function A = selectScale1
A = rand(1,1)*(0.09)+0.9;
end
function A = selectScale2
A = rand(1,1)*(0.09)+1.01;
end
well, the above without comments before the shear function handles

### Categories

Find more on Historical Contests in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!