I am running a model for predicting water temperatures for a certain location and the model requires some initial inputs for the meteorological conditions. The inputs that the user must change are stored in a file with an extension .NML. I would like to access this file (from matlab) and run the model with a range of values for a specific variable. For example, there is one variable called ‘input_slope’ which the user must specify. I would like to run the model with a number of different values for this variable e.g. from 1:100 then run the model (application file) and compare the model outputs to my observed values.
I am really new to this and would like to know how I could start with altering an input file in matlab and then execute the model with these new values?
Thank you for your time.
If you want to alter an input file in Matlab, I would recommend the
Clike file IO functions likefopen,fgetl, and friends. Here’s a snippet I modified from the online docs that I use as a pattern often:Some would complain about not initializing the size of the cell array,
file_data, but for now let’s just get up and running. The cell array will contain a string for each line in your file with the newline removed. You can access the string like so:Then
stris a character array with your data. You can use textscan to get numbers, strings, etc. from thestrvalue.If you need to write out data, you could try something like:
Looks like this is an externally executable program so I would recommend using the system command to execute and get the return value from the program. I’m not sure how new you are to all this, so please let me know if this is helpful or not.