If I understand correctly what you are trying to achieve, it's doable (kinda) but it will need calibration.
First you want to work on hsv space, you can do this with rgb2hsv
On HSV space, 'V' or 'value' will give you the intensity of light of a given pixel. This will be the value you want to plot in order to get the graph you show. You can get either the average over each column of pixels, or just analyze the center row, whatever works better for you.
Now, the interesting part. How to get the x axis values of your graph. Theoretically speaking, your prism will separate the light into specific wavelengths and each one will have a unique 'H' or 'hue' value, related by
Hue = (650 - wavelength)*240/(650-475)
more about it here
But this will only work in ideal lighting conditions and if your camera is sensitive enough and its ccd have true green, red and blue, which I don't know how to test. Not to mention that the wavelength you are going to see in your monitor is also dependant on the calibration of your monitor, so I wouldn't trust it.
You can kind of check how pure and ideal is each pixel by the value of 'S' or 'saturation'. The higher the better.
What I would recommend you to do, it's to calibrate it by hand. Look at your spectrum and mark with a pencil or something where are colors that you know their wavelength, and then use those marks to define the x-axis of your graph.
I forgot to mention, you only need to make the calibration once, once you know which wavelength goes with which hue in your camera, you could do the setting automatically, or even a scatter(hue_wavelenght,value)
of all your pixels may work