title: R code to MATLAB
body: <p>Here is a code in <code>R</code>, I would like to run it with <code>MATLAB</code>, optimizing if possible.</p>
  
  <pre><code>require(lattice)
  #
  set.seed(42)
  
  # parameters for distribution of class 1
  a &lt;- 0
  b &lt;- 1
  # parameters for distribution of class 2
  c &lt;- 3
  d &lt;- 1
  
  x &lt;- c(sort(rnorm(1000,mean=a,sd=b)),sort(c(rnorm(1000,mean=c,sd=d))))
  y &lt;- c(dnorm(x[1:1000],mean=a,sd=b),dnorm(x[1001:2000],mean=c,sd=d))
  labels &lt;- factor(rep(c("class 1","class 2"),each=1000))
  
  dat &lt;- data.frame("x"=x,"density"=y,"groups"=labels)
  xyplot(density~x,data=dat,groups=labels,type="b",auto.key=T)
  </code></pre>