I have a main function which outputs image I, J. I need to read these I, J as inputs in another function (comb.m). I have tried declaring I, J as global but when I run comb.m, it's showing undefined variable I, J. How to call it correctly?
I think that you don´t need to define them as global variables. The common use of matlab functions is like this: comb.m must have declared those parameters as inputs: function [output1, output2] = comb (I, J)
If the syntax of Matlab does not work, perhaps you have to re-install it. It MUST work, by definition. You can start programming simple functions to understand how it works. If you have problems, please attach the code and perhaps we can help you.
What Martin explained must work. If the problem retains Why don't you integrate the second function with the main program as the comb.m definitely requires the outputs of main program.
You can use evalin('workspace','var'). You can specify the required workspace. Other way is to save to a temp MAT file the required variables and then load them in the function you are interested in.
We tend to use a lot the second solution suggested by #Vijay Yadav: Saving into a .mat file. Works fine. Always. And it is simple. The solution suggested by #Martín Martínez Villar should also work, but sometimes you don't want to modify the original function to make it produce outputs...
You don't call variables. Functions are called. I believe the correct term is to reference a variable. All you have to do is to make sure that the variable you want to reference is in the right scope. Saving the contents of the variable to a file is bad programming practice. Making the variable global is also bad programming practice but might be necessary sometimes. To give proper a solution would require to take a look at the code.
I would suggest using any of "real" programing languages like C++. It gives you much more power and the syntax is probably much better defined. I would suggest Qt as the environment since it provides huge help in image processing.