tutorial code for octave gives me weird error

Viewed 20
% create GMM
mu = [0; 5];
sigma = cat(3, 1, 2);
p = [0.5; 0.5];
gmm = gmdistribution(mu, sigma, p);

% view PDF
ezplot(@(x) pdf(gmm,x));

I'm trying to run this small tutorial code since i'm new to octave

but everytime I run this code it gives me error

error: gmdistribution.pdf: X has 500 columns instead of 1

what does this error mean?

How do I fix it?

1 Answers

The error is effectively telling you that you passed a horizontal vector to the gmmdistribution.pdf function, instead of a vertical one, which is what it expects.

This is because ezplot internally generates a horizontal vector of 500 points on the x-axis to plot your graph.

Therefore you can 'transpose' x when you use it in your anonymous function to, get it in the right orientation:

ezplot(@(x) pdf(gmm,x.'));

enter image description here

Related