how to import a lot of data files

1 次查看(过去 30 天)
hello i want to import to matlab a lot of data files with one line to write on MatLab instead of that all line.
  • load aae20100101dmin.min
  • load aae20100102dmin.min
  • load aae20100103dmin.min
  • load aae20100104dmin.min
  • load aae20100105dmin.min
  • load aae20100106dmin.min
  • load aae20100107dmin.min
  • load aae20100108dmin.min
  • load aae20100109dmin.min
  • load aae20100110dmin.min
  • load aae20100111dmin.min
  • load aae20100112dmin.min
  • load aae20100113dmin.min
  • load aae20100114dmin.min
  • load aae20100115dmin.min
  • load aae20100116dmin.min
  • load aae20100117dmin.min
  • load aae20100118dmin.min
  • load aae20100119dmin.min
  • load aae20100120dmin.min
  • load aae20100121dmin.min

采纳的回答

Geoff Hayes
Geoff Hayes 2014-9-15
Aliaa - try the following
for k=1:21
filename = sprintf('aae201001%02ddmin.min',k);
load(filename);
end
The above code builds the filename on each iteration of the loop, and then loads the file.
  2 个评论
aliaa madbouly
aliaa madbouly 2014-9-15
thank you so much Geoff :D
can you tell me too how to do this line in one
and can you explain more what did u do in the previous code and thanks.
  • x001=aae20100101dmin(:,4);
  • x002=aae20100102dmin(:,4);
  • x003=aae20100103dmin(:,4);
  • x004=aae20100104dmin(:,4);
  • x005=aae20100105dmin(:,4);
  • x006=aae20100106dmin(:,4);
  • x007=aae20100107dmin(:,4);
  • x008=aae20100108dmin(:,4);
  • x009=aae20100109dmin(:,4);
  • x010=aae20100110dmin(:,4);
  • x011=aae20100111dmin(:,4);
  • x012=aae20100112dmin(:,4);
  • x013=aae20100113dmin(:,4);
  • x014=aae20100114dmin(:,4);
  • x015=aae20100115dmin(:,4);
  • x016=aae20100116dmin(:,4);
  • x017=aae20100117dmin(:,4);
  • x018=aae20100118dmin(:,4);
  • x019=aae20100119dmin(:,4);
  • x020=aae20100120dmin(:,4);
  • x021=aae20100121dmin(:,4);
  • x022=aae20100122dmin(:,4);
  • x023=aae20100123dmin(:,4);
  • x024=aae20100124dmin(:,4);
  • x025=aae20100125dmin(:,4);
  • x026=aae20100126dmin(:,4);
  • x027=aae20100127dmin(:,4);
  • x028=aae20100128dmin(:,4);
  • x029=aae20100129dmin(:,4);
  • x030=aae20100130dmin(:,4);
  • x031=aae20100131dmin(:,4);
Geoff Hayes
Geoff Hayes 2014-9-15
Aliaa - the previous code just uses sprintf to build a the filename string
sprintf('aae201001%02ddmin.min',k);
The %02d% indicates that the integer that will be inserted into the string should be padded with up to two zeros.
As for what you wish, creating separate local variables for each file read in, I don't recommend that. Instead, I think that you should just store all of this data into a matrix or cell array (if the fourth column of each loaded matrix has a different number of elements)
% store the data in a cell array
numFiles = 31;
data = cell(numFiles,1);
for k=1:numFiles
filename = sprintf('aae201001%02ddmin.min',k);
S = load(filename);
data{k} = S(:,4);
end

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by