load a file with 'dir'

1 次查看(过去 30 天)
Hello,
I want to load a file containing multiple data disorganized and I do not know why I get an error message on the load function. Someone would have an idea?
thank you
clc
clear all
close all
%--exercice2----------------------
contenu = dir('C:\Users\williot\Dropbox\UQTR 2013 - 2015\Matlab\MatLab EPK6064\Fichiers_Travail2');
for file = 1:length(contenu)
if strcmp(contenu(file).name,'.')==0 && strcmp(contenu(file).name,'..')==0
file_name = contenu(file).name;
load(file_name)
end
end
??? Error using ==> load Unable to read file Chronique_DataFRP_sujet04.mat: No such file or directory.
Error in ==> exercice2__a_williot at 12 load(file_name)

采纳的回答

James Tursa
James Tursa 2015-4-17
编辑:James Tursa 2015-4-17
You are getting the results of dir from a different directory than the current directory. I.e., you explicitly put the path in the string argument to dir. So the file_name in question exists in that directory, but not in the current directory. You either need to use the full path name for the file to load it, or cd to that directory. E.g.,
load(['C:\Users\williot\Dropbox\UQTR 2013 - 2015\Matlab\MatLab EPK6064\Fichiers_Travail2\' file_name])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by