我写了以下代码:
function [a1,b1,a0,b0] = Conformal_2D(x_input,y_input,X_output,Y_output)
%%
% Calculates parameters $a,b,a_0,b_0$ in the following equation using least
% squares
%%
%
% $$X=a_1x+b_1y+a_0$$
%
% $$X=-b_1x+a_1y+b_0$$
%%
% *Arguments:*
%
% x_input is a $n\times 1$ matrix containing x coordinate of control points
% in the input space
%
% y_input is a $n\times 1$ matrix containing y coordinate of control points
% in the input space
%
% x_output is a $n\times 1$ matrix containing x coordinate of control points
% in the output space
%
% y_output is a $n\times 1$ matrix containing y coordinate of control points
% in the output space
%%
NumberOfPoints = size(x_input,1);
A = zeros(2*NumberOfPoints,1); % Coefficient matrix in AX = L
L = zeros(2*NumberOfPoints,1); % Right-hand matrix in AX = L
for i = 1:NumberOfPoints
A(2*i-1,1:4) = [x_input(i,1) y_input(i,1) 1 0];
end
end
当我按下“发布”按钮时,我得到:
这条线有什么问题?
不确定这是否是最好的解决方法,但我设法使用以下脚本发布该功能。当然,您将使用自己的条目x_input,y_inpyt等。确保将以下脚本保存在未命名为Conformal_2D.m的文件中。
Conformal_2D([3;2;1],[5;6;7],[11;12;13],[14;15;16]);
function [a1,b1,a0,b0] = Conformal_2D(x_input,y_input,X_output,Y_output)
%%
% Calculates parameters $a,b,a_0,b_0$ in the following equation using least
% squares
%%
%
% $$X=a_1x+b_1y+a_0$$
%
% $$X=-b_1x+a_1y+b_0$$
%%
% *Arguments:*
%
% x_input is a $n\times 1$ matrix containing x coordinate of control points
% in the input space
%
% y_input is a $n\times 1$ matrix containing y coordinate of control points
% in the input space
%
% x_output is a $n\times 1$ matrix containing x coordinate of control points
% in the output space
%
% y_output is a $n\times 1$ matrix containing y coordinate of control points
% in the output space
%%
NumberOfPoints = size(x_input,1);
A = zeros(2*NumberOfPoints,1); % Coefficient matrix in AX = L
L = zeros(2*NumberOfPoints,1); % Right-hand matrix in AX = L
for i = 1:NumberOfPoints
A(2*i-1,1:4) = [x_input(i,1) y_input(i,1) 1 0];
end
end
发布时,MATLAB默认运行代码。当然,您的函数具有在这种情况下不会设置的输入参数(请参阅this other question)。
有几种方法可以解决这个问题。 Juanchito's answer说明了一个:不发布函数,发布脚本。
或者,发布函数而不执行它:
publish('Conformal_2D.m','evalCode',false)
或者,在执行函数内容之前,给MATLAB提供正确的声明来评估:
publish('Conformal_2D.m','codeToEvaluate','x_input=1; y_input=2; X_output=3; Y_output=4')
(当然,请调整这些值)。