Hello, I have 4 .mat files including tens of variables of the same name. How I can rename the variables after loading each file in a new script file. I have read similar link but didn't work well.
Thanks
Best Answer
Use either theload ormatfile functions with an output argument. The structure format can keep the variable names separate.
For instance, if you have variable names‘x’,‘y’, and‘z’ in each.mat file, you can load them all into your workspace without ambiguity. If your.mat files are namedA.mat andB.mat, load them as:
A = load('A.mat');
B = load('B.mat');
then:
A.x % ‘x’ from A.mat
B.x % ‘x’ from B.mat
and so forth for the rest of them. You have to refer to them as such in the rest of your code, but they will be uniquely identified that way.
works. It's probably neater to merge the structs and do a single save, but I couldn't remember off the top of my head how to do that so if this is a one-time operation then that solution works fine.
Best Answer