Mathematica Import multiple files into Mathematica

Click For Summary
To import multiple files into Mathematica as a nested list, the user initially struggled with a method that only allowed for single file imports. After some exploration, the solution was found to be straightforward: using the Map function to apply Import to a list of filenames. The final code implemented was "alldata = Map[Import, filenames];" where filenames contained the list of files. This approach effectively loads all files into a single variable as desired. The issue was resolved with a simple adjustment to the import method.
ChristinaJ
Gold Member
Messages
34
Reaction score
1
Hi,

I'm trying to import multiple files into Mathematica. Each file is a 2d matrix and I would like to import multiple files into a nested list. So far I have something that only allows me to load a single file.

In:= SetDirectory["/directory"];

In:= filenames = FileNames[]
Out:= {file1,file2,file3, ...}

In:= loaddata[filenumber_] := Import[Part[FileNames[], filenumber]]

I have a strong suspicion that this is very simple but I just can't see the answer.

Thanks in advance for any help,
Christina
 
Physics news on Phys.org
[SOLVED]

I was right, very simple to solve. Now I have

alldata = Map[Import, filenames];

where filenames={file1,file2,file3,...}
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
13K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 52 ·
2
Replies
52
Views
13K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
26K