1

I have three functions and i want two variables to run through all the functions. I tried doing this:

R = rot(mir(sca(P(1,:),P(2,:))));

however i get this error:

Error using mir (line 2)
Not enough input arguments.

Any suggestions?

%rot.m
function rot = rot(x,y)
    rot = [ cos(pi/6)*x-sin(pi/6)*y; sin(pi/6)*x+cos(pi/6)*y ];

%mir.m
function mir = mir(x,y)
    mir = [x;(-y)];

%sca.m
function sca = sca(x,y)
    sca = [2*x;2*y];
4
  • 2
    It seems that you're passing only one arguments to function mir (the result of sca), but it requires more. Commented Mar 7, 2013 at 15:43
  • Yes, and that's the core of my problem. The inner function (sca) has two arguments, and passes two arguments (at least that's my intention) sca.m looks like this, and the other functions are very similar: function sca = sca(x,y) sca = [2*x;2*y]; Commented Mar 7, 2013 at 15:47
  • Can you add the syntax of mir and sca in your question, and elaborate a bit more on your intention? Commented Mar 7, 2013 at 15:50
  • Thanks. I've added the functions now. I want to transform an array using three different functions at once. I also need to be able to switch the functions. Commented Mar 7, 2013 at 15:54

2 Answers 2

1

You should not be surprised about the error. Function mir expect two parameters (in fact, all of your functions expect that), but you provide only one. Mind you, a matrix is considered one parameter. You can do either of the following to correct the problem:

  1. Redefine mir to accept one parameter and split it inside the function into two separate variables

  2. Redefine sca to return two values:

    function [outx, outy] = sca(x, y)
        outx = 2 * x;
        outy = 2 * y;
    

    and then pass them to mir like so:

    [scax, scay] = sca(x, y);
    mir(scax, scay);
    

Obviously, the same needs to be done to function rot as well.

Sign up to request clarification or add additional context in comments.

Comments

0

In MATLAB if you have more then one output argument you have to explicitly specify the output variables. By default function always returns one (the first) argument.

In your situation one choice can be to change definitions of your functions in such a way that they receive only one input argument as a matrix. For example:

%mir.m
function mir = mir(xy)
    mir = [xy(1,:); -xy(2,:)];

or even easier in this case (you can simplify other functions as well):

function xy = mir(xy)
    xy(2,:) = -xy(2,:);

I hope you got the idea.

Then you can run:

R = rot(mir(sca(P(1:2,:))));

If you cannot change your function definitions for some reason, you will have to split the one-line call to three function into 3 lines:

S = sca(P(1,:),P(2,:));
M = mir(S(1,:),S(2,:));
R = rot(M(1,:),M(2,:));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.