ofxMath -particlesExample change number of particles dynamically

I am running the particles example from /examples/math/particlesExample. I want to learn to implement a GUI to control the number of particles.

I can successfully implement a GUI and intSlider:

//ofApp.h
    void numParticlesChanged(int & numParticles);
    ofxIntSlider numParticles;
    ofxPanel gui;

//ofApp.cpp, within void ofApp::setup(){
    gui.setup();
    numParticles.addListener(this, &ofApp::numParticlesChanged);
    gui.add(numParticles.setup("particles", 300, 10, 1500)); //MH initial, min, max
    //int num = 300;
    int num = numParticles;
    p.assign(num, demoParticle());

//Particles changed function
    void ofApp::numParticlesChanged(int &numParticles){
        //DO SOMETHING HERE
    }

The problem is that the number of particles is established within the setup function, so I’m not sure how to update the number of particles within the numParticlesChanged function. I can’t just call ofApp::setup() again, because it will just revert to the default number in the GUI. I’ve also tried p.size(numParticles) and p.assign(numParticles,demoParticle());

How do I accomplish this?

You can put numParticles listener inside update function and check the condition there.