Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How can I use many input arguments(up to 20) to my function?

Asked by Nopparat

Nopparat (view profile)

on 10 May 2013

I write my function which needs a lot of input arguments. For example, function my_function=test(input1,input2,input3,....input20)

This function can call only first 9 input arguments so I can't use input argument#10-20. So, please tell me how can I use these input in my function. Thank you very much

0 Comments

Nopparat

Nopparat (view profile)

Products

No products are associated with this question.

2 Answers

Answer by the cyclist

the cyclist (view profile)

on 10 May 2013

Variable-length input argument lists might solve your problem:

http://www.mathworks.com/help/matlab/ref/varargin.html

0 Comments

the cyclist

the cyclist (view profile)

Answer by Youssef KHMOU

Youssef KHMOU (view profile)

on 10 May 2013
Edited by Youssef KHMOU

Youssef KHMOU (view profile)

on 10 May 2013

hi,

you can use a single input which is multidimensional , here is an example :

i want to compute the powers consumed by 9 different devices in the house based on the current, voltage and the alpha angle :

 function Y=Myfunction(M)
 Y(1)=M(1,1)*M(1,2)*cos(M(1,3));
 Y(2)=M(2,1)*M(2,2)*cos(M(2,3));
 ......
 Y(9)=M(9,1)*M(9,2)*cos(M(9,3));

so the single input is ( as axample ):

 M =
    0.1622    0.7482    0.0782
    0.7943    0.4505    0.4427
    0.3112    0.0838    0.1067
    0.5285    0.2290    0.9619
    0.1656    0.9133    0.0046
    0.6020    0.1524    0.7749
    0.2630    0.8258    0.8173
    0.6541    0.5383    0.8687
    0.6892    0.9961    0.0844

0 Comments

Youssef  KHMOU

Youssef KHMOU (view profile)

Contact us