how can I generate a Bernoulli block mixture model in matlab?
First, $x_{ij}$ is not a bernoulli random variable. In the text, $x_{ij}$ is described as real valued. Also, the dimensions of $z$ and $w$ are incorrect.

The text indicates that we're drawing a matrix of data call it $X (n\times d)$ such that $X_{i,j}=x_{ij}$.

A particular entry has distribution $x_{ij} \sim f(\alpha_{z_i, w_j})$. Where $\alpha$ is some given matrix of parameters. The maximum row index of $\alpha$ is $g$. The maximum column index of $\alpha$ is $m$. So $\alpha$ is $g \times m$.

All that remains is to pin down the indices $z$ and $w$. These are vectors rather than matrices since they have a categorical distribution, for example $z_i$ should be an integer between $1$ and $g$.

Putting this together we need to:


Draw $z$, a vector of length $n$, by $z_i \sim \text{Cat}(\pi), i=1,...,n$
Draw $w$, a vector of length $d$, by $w_j \sim \text{Cat}(\rho), i=1,...,d$
Draw $X$, an $(n\times d)$ matrix, by $x_{ij} \sim f(\alpha_{z_i, w_j})$