Timeline for Efficiently initialize list of consecutively named variables for file import
Current License: CC BY-SA 3.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 20, 2013 at 13:14 | comment | added | bill s |
One major difference is that when you Import using the above code, the imported information is assigned to allFiles[[1]], allFiles[[2]], etc. When you Get , the information is evaluated.
|
|
Jun 20, 2013 at 12:09 | comment | added | fpghost |
@bills But how is that different to Import ? Would Import produce an error instead or something?
|
|
Jun 20, 2013 at 12:07 | vote | accept | fpghost | ||
Jun 20, 2013 at 12:02 | comment | added | bill s | If you read in two definitions for the same thing, then you are going to have to be careful which one is in effect (probably the last one read and executed). I don't think there's anything wrong with this, but you need to be careful that subsequent code is using the definitions you think it is using. | |
Jun 20, 2013 at 11:58 | comment | added | fpghost |
@bills Do you mean if I have two contradictory definitions for, say, f[2] I will hit issues with Get but not Import ? What is the behaviour of each in that case? thanks..
|
|
Jun 20, 2013 at 11:50 | comment | added | bill s |
@fpghost -- if you are going to be reading in definitions then Get might be better, but you also need to be careful about conflicting definitions.
|
|
Jun 20, 2013 at 11:48 | comment | added | bill s |
@bobthechemist -- I'm not really sure what's in the files, so I added the suggestion of using Get in case this is preferable to Import . Either should work -- this just answers the part about getting all the file names... not what you're going to do with the information after it's read in!
|
|
Jun 20, 2013 at 11:47 | comment | added | fpghost |
@bobthechemist @bill s I have no idea if using Get is dangerous here? It's just that using Import doesn't seem to set the definitions that I mentioned in the my previous comment.
|
|
Jun 20, 2013 at 11:45 | comment | added | fpghost |
@bill s Yes, sorry I was being an idiot. I think it did not work the way you had it because of Import vs. Get perhaps. My files contains lots of definitions like f[2]=3.4234324, f[3]=3.35555533,.... etc and using Import for some reason did not set these in the workbook like normal, but when I changed to Get things are defined..
|
|
Jun 20, 2013 at 11:44 | comment | added | bobthechemist |
Based on the variable names used by the OP, should Import be used instead of Get ? It seems to me that unless the logfile has commands to be executed, Get should be avoided in this case.
|
|
Jun 20, 2013 at 11:41 | history | edited | bill s | CC BY-SA 3.0 |
added 333 characters in body
|
Jun 20, 2013 at 11:36 | comment | added | bill s |
You misunderstand how it works, I think. This reads the names of all files (in the specified directory) that have the extension ".txt" and places these names in a list called fileNames . Then you read in the files from this list. They can be be named anything at all, as long as they have the specified extension.
|
|
Jun 20, 2013 at 11:27 | comment | added | fpghost |
Thanks, this works if you just have files called 0,1,2,3... and change the code as: fileNames = FileNames["*", path]; allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}]; but not otherwise as the files are not just named by numbers. Is there a way to concatonate ".txt" onto num when you do the final read in?
|
|
Jun 20, 2013 at 11:06 | history | edited | bill s | CC BY-SA 3.0 |
added 117 characters in body
|
Jun 20, 2013 at 10:18 | history | edited | bill s | CC BY-SA 3.0 |
added 77 characters in body
|
Jun 20, 2013 at 9:59 | history | answered | bill s | CC BY-SA 3.0 |