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
回答 (1 件)
Guillaume
2016 年 11 月 22 日
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.
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!