Extracting all elements from a vector without knowing the length

Hi!
I am writting a function that has for parameter a probability distribution and all of its parameter in a vector. At some point I need to create the distribution usisng makedist. However I need to imput the parameters but the number of parameters depends on the distribution. The function will go something like this:
function output=creatingDist(distribution,parameters)
dist=makedist(distribution,parameters(1),...,parameter(n))
...
end
Anyone know how to extract the parameters into the function without knowing exactly the length of the vector)
Thank you very much

Answers (1)

That is a fairly common operation in matlab. Use the expansion of cell arrays into comma separated lists:
function output = creatingDist(distribution, parameters)
%assuming parameters is a cell array of name-value pairs not a vector of numbers as the question seem to imply
dist = makedist(distribution, parameters{:}); %expand cell array into comma-separated list.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 22 Nov 2016

Answered:

on 22 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!