Files won't consistently save in current working directory

6 visualizaciones (últimos 30 días)
ANetTow
ANetTow el 8 de Feb. de 2013
I am running Matlab R 2012b on Microsoft Windows XP Professional.
I frequently save data or figures to file while running analyses. Previously, if I did not specify a full pathname for the file, it would save in my current directory.
Since I upgraded to 2012b, I find that frequently my files aren't where I expect them to be. There seems to be no consistent pattern to the directory in which they end up, either.
For example, take directory A. A has children B1 and B2. B1 has children C1 and C2. B2 has children C3 and C4. B2 and its children are in the Matlab path, the others are not.
Say I am running a script in directory C1. Files generated in that script have ended up in its sibling C2, its parent B1, it's grandparent A, it's uncle B2, and even it's cousins C3 and C4. Recently, I ran a loop 8 times. Six of the files ended up in a sibling directory. The last two ended up in the current working directory.
To avoid playing hide-and-seek with my files, I am going to always use full path names. However, I am concerned this might be a symptom of a larger problem. If so, is it likely to be with Windows or Matlab?

Respuestas (1)

Jan
Jan el 8 de Feb. de 2013
I'm convinced, that Matlab saves the files in the current directory. When the files appear at unexpected locations, there are some cd() commands hidden in your code. Neither Matlab 2012b nor Windows XP change the current folder magically.
Usual locations for unexpected changes of the current directory are callbacks of timer() or GUI elements.
However, using absolute path names is the right way.
  2 comentarios
ANetTow
ANetTow el 8 de Feb. de 2013
Editada: ANetTow el 8 de Feb. de 2013
Perhaps. Does tic call timer()? Do figures count as a GUI?
Just now, I executed a very simple script: 1) Load a .mat file (from the same directory as the script). 2) Use a for loop to take selected items from a structure in that file based on an ``if strcmp()'' query 3) Save the new structure in a .mat file.
My new file ended up in the Matlab directory. Where I never store my work.
the cyclist
the cyclist el 8 de Feb. de 2013
Consistent with Jan's answer, I have never had this behavior where I could not trace it to an unexpected cd(). (I've never seen it happen just using tic and toc.)
I wonder if you could boil this down to the simplest possible script that you can get to replicate the behavior, and then post that. (It may also help you debug it, by reducing it to the bare bones.)

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by