A function that creates a transformation matrix
Mostra commenti meno recenti
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 Commenti
At the moment, MATLAB only sees "values" as input to the function to_MNI which should be a vector with 12 elements.
Why do you reset values to {X_loc, Y_loc,Z_loc,m0n0,m0n1,m0n2,m1n0,m1n1,m1n2,m2n0,m2n1,m2n2,CD} with variables X_loc, Y_loc,Z_loc,m0n0,m0n1,m0n2,m1n0,m1n1,m1n2,m2n0,m2n1,m2n2,CD that "fall from the sky" ?
Reuben Addison
il 27 Ott 2022
Torsten
il 27 Ott 2022
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 ?
Risposte (1)
Steven Lord
il 27 Ott 2022
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 %.
3 Commenti
Reuben Addison
il 27 Ott 2022
Modificato: Reuben Addison
il 27 Ott 2022
Steven Lord
il 27 Ott 2022
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.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!