Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to create multidimensional arrays of distribution objects?

Asked by Alex on 2 Oct 2013
Latest activity Commented on by Alex on 3 Oct 2013

Hi I am just working on a larger program that works with two random distributed Variables:

X for incoming products(Production) Y for outgoing products(Demand)

both random variables have 2 parameters, so a and b belong to X and c and d belong to Y. I am now working on a combination of both and need a combined distribution stored in a 4 dimensional array to reflect all possible combinations. My initial guess to create an "empty" array of the matching dimensions was just:

    a=[1 2 3 4];
    b=[5 6];
    c=[7 8 9];
    d=[1 2 3 4 5];
    for i=1:length(a)    
        for j=1:length(b)    
            for k=1:length(c)    
               for l=1:length(d)    

the problem is now that matlab seems to have no default distribution-object included in the libraries and following error occurs:

During array expansion: No default is defined for class 'prob.NormalDistribution'. Method 'getDefaultScalarElement' in superclass prob.ProbabilityDistribution is missing or incorrectly defined.

I was lucky find a solution for 2 dimensions that just sets the elements before a default element is needed and i expanded this to a 3 dimensional array. However, if i try to expand the solution in the same way to 4 dimensions the error occurs again:

a=[100 5 5 7];   
b=[10 4 4 5 6];   
c=[100 2 6 7 9 9];   
d=[1 4 5 5]; 
for i=1:length(a)   
    for j=1:length(b)  
        test (i,j)=makedist('normal',0,0);  
for i=1:length(a)   
    for j=1:length(b)  
        test2 (i,j,:)=makedist('normal',0,0);  
        for k=1:length(c)   
            test2 (i,j,k)=makedist('normal',0,0);             
for i=1:length(a)   
    for j=1:length(b)  
        test2 (i,j,:,:)=makedist('normal',0,0);  
        for k=1:length(c)   
            test2 (i,j,k,:)=makedist('normal',0,0);   
            for l=1:length(d)  

While the first two versions are running perfectly, even as intended and give the matching distribution-object arrays, but the 4 dimensional one gives following error:

During array expansion:  
No default is defined for class 'prob.NormalDistribution'.  
Method 'getDefaultScalarElement' in superclass prob.ProbabilityDistribution is missing or incorrectly defined.
Error in Untitled (line 29)

When i define the 3 dimensional array first, set test3=test2, the error shifts to the line


as soon as d=[ ] has more than one element. i also tried to set the d loop around the other 3 loops but the error always occurs when the pointer of the fourth dimension shifts to 2. I dont know why this error occurs only with 4 dimensions, to my understanding it should also occur with 3 dimensions, or both versions should run propperly, i cant see why one works and the other one not.

It would be very kind if somebody could help me with this problem or give me a hint how to create this AxBxCxD array of distribution objects in another way. Thank you for your help


Matt J on 2 Oct 2013

Please use the

toolbar button to format your code (and error messages) more readably.

Alex on 2 Oct 2013

Sorry, I didnt see that button, i reformated it, thank you



1 Answer

Answer by Tom Lane on 2 Oct 2013
Accepted answer

This looks like something that we should fix in a future release. Meanwhile, perhaps you would find this work-around useful:

a = makedist('normal');           % create a single distribution object
a = repmat(a,[2 3 4 5]);          % expand it to the desired size
a(2,3,4,5) = makedist('Weibull'); % fill in the values you really want

1 Comment

Alex on 3 Oct 2013

Ah great, that is the perfect solution, thank you very much!

Tom Lane

Contact us