Assuming "figure 2" means an image loaded into Matlab, you can add salt and pepper noise to the image using the imnoise function that is included in the Image Processing Toolbox. Here's an example code snippet:
main.m193 chars4 lines
The second argument to imnoise specifies the type of noise to add (in this case, "salt & pepper") and the third argument is the probability for both salt and pepper noise.
gistlibby LogSnag