Tip for loading external data programatically
Hi everyone,
I have a tip I think might be helpful to others as it is helpful to me to load external data files in my Activate models without having to worry about the file path to the data if the model is moved/shared with someone else.
If you have data in external files (e.g. like a .mat file or whatever), you may load this into Activate with commands in the Model or Diagram Contexts. Here you need to either have a relative or absolute path to the file:
load('my_model_data.mat') <-- must be in the directory set in 'File Browser'
or
load('C:\my_absolute_path\my_model_data.mat')
However, if you want to make your model more generic and portable to other directories, you can use the command 'bdeGetCurrentModelFilePath', which returns the same path as your Activate model. Then, you can define the model data relative to your model path (e.g., like in the same directory, as below):
my_path=bdeGetCurrentModelFilePath()
file_path=strcat(my_path,'/../my_model_data.mat')
load(file_path);
This is nice when sharing models with others so the paths can be set automagically.
Hope this helps someone...
Cheers,
Andy