Taking a snapshot of an image upon a button click can be achieved in the following two ways:
1.Create a simple appdesigner application with the above code, and a button. Associate a callback function to the button, that gets executed when this button is clicked, and captures the snapshot. See app_ex for a simple appdesigner application example.
2. Another way to achieve this is by using the Image Acquisition Toolbox's Image Acquisition Tool.This tool provides a GUI and helps preview, configure, acquire, and save image data. The Image Acquisition tool can be accessed by using the 'imaqtool' command or by selecting Image Acquisition on the Apps tab. Visit Imaqtool to know more about how to use the Image Acquisition tool.
Hope this helps!