Why is MATLAB 7.0.4 (R14SP2) unable to recognize my files, when I use the COPYFILE command in my script?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I run a script, myfile.m, which contains the following code:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
type(temp_file);
I receive the following error :
??? Error using ==> type
tp103239 is a directory.
Error in ==> myfile at 7
type(temp_file);
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
This has been verified as a bug in MATLAB 7.0.4(R14SP2) in the way COPYFILE notifies MATLAB about the changes made to a destination directory.
The followings are some workarounds to resolve the issue:
1. Using an absolute path name:
Use an absolute path name as an input to functions(TYPE in this case) accessing the destination directory as follows:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
type(fullfile(FullPathTempDir,destinationFile));
2. Use WHICH or EXIST on the path of the destination directory as follows:
FullPathTempDir = tempname;
[temp_dir temp_file] = fileparts(FullPathTempDir);
mkdir(FullPathTempDir);
destinationFile = [temp_file,'.m'];
origPath = addpath(FullPathTempDir);
copyfile('hSampleDisp.m',fullfile(FullPathTempDir,destinationFile));
which temp_file
type(temp_file);
3. CD to the directory, in which the file is located, before accessing the file.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!