Sepideh Abadpour
Sepideh Abadpour

Reputation: 2598

"Not enough input arguments" when publishing MATLAB commands

I've written the following code:

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

When I press 'Publish' button, I get:

enter image description here

What's the problem with that line?

Upvotes: 0

Views: 320

Answers (2)

Cris Luengo
Cris Luengo

Reputation: 60494

When publishing, MATLAB runs the code by default. Of course, your function has input arguments that will not be set in this case (see this other question).

There are a few ways around this. Juanchito's answer illustrates one: don't publish a function, publish a script.

Alternatively, publish the function without executing it:

publish('Conformal_2D.m','evalCode',false)

Or, give MATLAB the right declarations to evaluate before executing the function's content:

publish('Conformal_2D.m','codeToEvaluate','x_input=1; y_input=2; X_output=3; Y_output=4')

(do adjust those values, of course).

Upvotes: 0

Juancheeto
Juancheeto

Reputation: 586

Not sure if this is the best workaround, but I managed to publish the function with the following script. Of course, you will use your own entries for x_input, y_inpyt, etc. Make sure that you save the following script in a file not named 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

enter image description here

Upvotes: 1

Related Questions