Extracting all elements from a vector without knowing the length
Mostra commenti meno recenti
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
Risposte (1)
Guillaume
il 22 Nov 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.
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!