@Vicki Ly: the best answer ( best in the sense fastest, neatest, least buggy, best practice as recommended by the MATLAB documentation and all MATLAB experts) is to simply pass your data as input and output arguments. For this you will need to define your function with input and output arguments. See the function help for more information on how to do that:
The introductory tutorials teach how to call functions correctly (with input and output arguments), and are highly recommended for all beginners:
"However, when I input or try ... and hit "Run","
That awful "Run" button has caused a continuous stream of beginners so much confusion because they try to run some function which requires inputs but that badly designed "Run" button does not provide their function with its required inputs. The best thing that can happen is that TMW removes the "Run" button from the toolbar. Until then the best thing that you can do is to ignore that button. Do NOT use it. When you want to run code, simply execute it from the command line by typing the script name, or the function name (along with any required input and output arguments) and then press enter. Or call it from another script/function/callback/class/.... but do NOT use that button. How to run scripts/functions is also explained in the introductory tutorials, which I highly recommend that you work through to learn basic MATLAB usage.