How can I later access the name of file B from A? When I call A, I only get the name of all fields, but not the name of the MAT File B
Best Answer
"From A", you can't; the data storedin a .mat file are totally independent of the (root) name given the file when it was created. The only way to create a connection would be to add another variable or field in the structure that contains the filename you're going to use whenSAVE the data. Of course, this runs the risk you don't update the field correctly or at all, so it's not a sure-fire method, either.
What's the problem you're actually trying to solve? If you have 'b.mat' to load the file, what's to keep from creating the link from that information to do whatever it is that you wish to do?
But the upshot is, there is nothing within a standard .mat file than the variables written to it; if you don't add information within the file if the filename that was used toload it is somehow lost it can't be told which file it was.
Using load with a return value will give you a struct with your data in it, but you can just get the data out of the struct. You can also do this in other ways, probably neater, but this should work and if it is a one-off operation efficiency or neatness doesn't really matter.
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