It's just MATLAB behavior and has been from the beginning...whether there's any chance TMW would even consider changing it would be a long shot I'd think, but one can always submit an enhancement request.
save/load with odd results
1 次查看(过去 30 天)
显示 更早的评论
I'm just wondering if this is really intentional, as I find the behaviour extremely weird. When saving a workspace/variable to a subfolder, it can happen that when reloading the workspace a different file is accessed due to matlabs partial filename concept.
As an example: Assume I have a Project with a few pathes:
- SubProject1
---> Data
------> ResultData.mat
- SubProject2
---> Data
Now, Subproject1/Data is on my path (for whatever reason). If I'm now in the Subproject2 folder and do:
save('Data/ResultData.mat','myResults');
load('Data/ResultData.mat','myResults');
My myResults variable will be the one which was stored in SubProject1/Data/ResultData.mat The reason is, that when looking for files, before looking for subfolders on the current working directory, MATLAB will search its path for any match with the current pattern, and since SubProject2/Data is not on the path, it will be skipped.
I'm not sure if its only me, but I find this behaviour extremely odd. I would always expect that a given file path is first assumed to be a relative file path befoe it is looked up as a partial file path on the matlab path. In particular, I would expect
save(x);
load(x);
to not change the workspace under any cicumstance (at least for all elements which can be saved/loaded and a non concurrent execution). The least I would expect, if the file is also somewhere on the path, while also being present as relative path in the local folder is that this throws a warning.
What's your opinion on this?
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!