Gregory,
I have a feature / implementation idea for the exo2mat and mat2exo functions. My idea revolves around how to implement variables what have their index in their name (e.g. blkXX, gvarXX, nvarXX, evarXX, ssfacXX etc)
If I want to loop through my variables I currently do one of two things:
clear
load('sample_output_matlab.mat'); %nnvars = 15
- This method uses the eval function to create a temporary variable for me to operate on. Of course, while the eval function does the job, it is clunky to use in this manner and can’t be compiled (always interpreted). http://www.mathworks.com/help/matlab/matlab_prog/string-evaluation.html
%% Method 2
for ii = 1:nnvars
varData = eval(['nvar' sprintf('%02d',ii) ';'])
end
- What I prefer to do is to transfer all the pertinent variables to cell arrays.
%% Method 3
% Convert nvarXX into an indexable cell array
NVAR = cell(nnvars,1);
for ii = 1:nnvars
NVAR{ii} = eval(['nvar' sprintf('%02d',ii) ';'])
eval(['clear nvar' sprintf('%02d',ii)])
end
% Can loop through variables serially
for ii = 1:nnvars
varData = NVAR{ii};
end
% Can loop through variables in parallel
parfor ii = 1:nnvars
varData = NVAR{ii};
end
In the workspace this would look like this:
![image](https://cloud.githubusercontent.com/assets/897294/14353417/36152592-fc96-11e5-8fd8-b331c211ab18.png)
As opposed to this:
![image](https://cloud.githubusercontent.com/assets/897294/14353422/3fa79e3c-fc96-11e5-8213-39e713b5ce10.png)
In addition to functionality, I like that it cleans up my workspace (Condenses hundreds of nvars, evars, gvars, ssfacs, ssnodes, sselems, blks etc into fewer variable icons)
Would it be possible to have exo2mat generate cell-arrays for the relevant variables? And could mat2exo convert .mat files with cell arrays? Maybe through a command line flag?
(I think it’s still good to list variables in the current manner, as I think it’s more accessible for “light-users” of Matlab who may not be accustomed to cell arrays.)
Best Regards,
G------ V-----