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!