Sunny,
As HPC said, I don't think you have to link the code, which I imagine would be quite difficult. You'll probably spend a lot more time doing that than running some sort of recursive script to hone in on your optimized value.
For similar tasks, I've used something along the lines of this code:
load(intitalValues.mat,'MFInputParams'); %load an initial set of modflow input parameters from a file
keepRunning=1; %initialize
while keepRunning==1 %run until desired criteria are met - you may want some error handling to prevent an infinite loop. You could also set this up as a parfor loop if you wanted to multithread.
generateModflowInputFiles(i); % this runs a series of functions to generate dis,nam,chd,etc files
dos('RunModflow.bat') %this runs modflow
[keepRunning,MFInputParams]=MakeDecision(readModflowOutput()); %this reads the output and decides whether the desired criteria have been met, and if not, creates a new set of modflow input parameters
end
good luck.