The attached MATLAB file "append_var.m" is an example of how you can achieve this functionality. Also download the two sample MAT files attached to execute this example. The process involves the following steps:
1. Load the first MAT file (matlab1.mat) and read all the variables into another variable, say “file1” (stored as STRUCT).
2. Next read all the variables in the second MAT file (matlab2.mat) into another variable, say “file2” using the WHOS command without actually loading them into the workspace.
3. Do a string compare to see which variables are common between the two MAT files. If there is a common variable name, save the variable in current MAT file to temp, and load the variable from the other MAT file into the workspace and append it to temp using the EVAL function. If not, at the end of the loop just load this variable into the workspace.
4. Finally, clear the unwanted variables and save the current set of variables in another MAT file (if needed) or just overwrite to another file and delete any unnecessary MAT files.
Best Answer