MATLAB: Save with identical file- and variable name

MATLABrename variablesave

I am saving data in Matlab to open it in a python script. For some reason this requires that the name of the variable and the filename are the same. For example, this works (saving as version 7.3 makes it possible to import in python without losing the structure):
data = data.(filename{1,1})
save('data', 'data', '-v7.3')
but this only allows me to save with the filename 'data' , which I can also not change afterwards, because then python won't read the file anymore.
I know I could use this method to save each file manually with a name that I want, but there is quite a large number of files involved. So I would like to re-write it in a way that uses the filename stored in the array filename automatically. I have the feeling this should be possible, but I can't get it to work yet…
I have tried many things like this:
for i = 1:n
filename = (filename{1,i});
name = strcat(filename);
name = data.(filename{1,i})
save(name, 'name', '-v7.3')
end
But for some reason it seems not to be possible to save a file with a filename that is identical to the variable name. I hope my problem is clear, any ideas would be greatly appreciated!

Best Answer

Assuming your Data is a structure containing your variables, here's one way to make file names = variable names:
Data = struct('A', 1, 'B', 2, 'C', [1 2 3], 'D', [1 3 ; 3 4]); %Example structure of data
Fields = fieldnames(Data);
for f = 1:length(Fields)
save(Fields{f}, '-v7.3', '-struct', 'Data', Fields{f});
end