MATLAB: How to automatically increment the values of the variable name in a From/To Workspace Block in Simulink 6.4 (R2006a)

simulink

WIth a model with several To/From Workspace Blocks, I would like to increase an index in the variable names each time the model is run.

Best Answer

The attached model, increment.mdl, loads three variables from the workspace (a0,b0,c0) and then saves them as (a1,b1,c1). The initial a0,b0,and c0 are saved in initial.mat. The script incrementVars.m will find the variables referenced in the To and From Workspace blocks and increment the variable names.
If you want this code run automatically, you can call this MATLAB file from the Model's StopFcn callback (File -> Model Properties -> Callbacks Tab -> StopFcn).