Extracting all elements from a vector without knowing the length
Mostrar comentarios más antiguos
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
Respuestas (1)
Guillaume
el 22 de Nov. de 2016
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.
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!