A function that creates a transformation matrix

조회 수: 4 (최근 30일)
Reuben Addison
Reuben Addison 2022년 10월 27일
댓글: Steven Lord 2022년 10월 27일
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
Reuben Addison
Reuben Addison 2022년 10월 27일
They wont fall from the sky, they are in the fuction
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에서 Object Containers에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by