A function that creates a transformation matrix

3 次查看(过去 30 天)
I want to create a matrix that transform a matrix into new coordinates but I am a getting an error with too many inputs
function A = to_MNI(m0n0, m0n1, m0n2, X_loc, m1n0, m1n1, m1n2, Y_loc, m2n0, m2n1, m2n2, Z_loc)
A = [m0n0 m0n1 m0n2 X_loc; m1n0 m1n1 m1n2 Y_loc;m2n0 m2n1 m2n2 Z_loc];
B = [0 0 CD 1]';
C = A*B;
end
%C_oord = to_MNI(-53.873,-15.673,62.626,0.669,-0.623,0.404,0.227,0.69,0.688,-0.707,-0.369,0.603,9.163,9.161)
  3 个评论
Torsten
Torsten 2022-10-27
But not in the code you supplied.
And why do you define "values" as input to the function if the variables "values" is made of are in the function itself ?

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2022-10-27
function A = to_MNI(values)
Your function accepts 1 input argument. You're calling it with 14. That's not going to work.
values = {X_loc, Y_loc,Z_loc,m0n0,m0n1,m0n2,m1n0,m1n1,m1n2,m2n0,m2n1,m2n2,CD}
None of the variables inside the curly braces are defined in your function at this point so this line of code will error. If you intended it to document the order in which the elements of the values input should be interpreted then make it a comment by starting the line with the percent symbol %.
Depending on what you're trying to do the makehgtform function may be of interest to you.
  3 个评论
Torsten
Torsten 2022-10-27
编辑:Torsten 2022-10-27
If you add "CD" to the list of input parameters and you call the function with 13 scalar inputs, the modified code should work.
Steven Lord
Steven Lord 2022-10-27
Okay, let's line up the definition and the call. The first character of each variable name in the function definition lines up with the corresponding value in your function call.
function A = to_MNI(m0n0, m0n1, m0n2, X_loc, m1n0, m1n1, m1n2, Y_loc, m2n0, m2n1, m2n2, Z_loc)
%C_oord = to_MNI(-53.873,-15.673,62.626,0.669, -0.623,0.404,0.227,0.69, 0.688,-0.707,-0.369,0.603,9.163,9.161)
You're passing in two more values (9.163 and 9.161) than you have input arguments. As Torsten said if you add CD as another input argument in the definition then you'll be closer. You also would need to remove one of the values with which you call the function.
You probably also want to return C from your function rather than returning A.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Analytics Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by