I want to upload a .txt file as a 1 column wave, this is what I have so far, I am not sure what the next steps would be. I have attached the .txt file that I am trying to upload.
From "I want to upload a .txt file as a 1 column wave", I am guessing that you want to concatenate all of the columns in the matrix wave created by LoadWave/G/M into a single 1D wave. After LoadWave/G/M, you can use Redimension to convert the wave to 1D. Something like:
String name = StringFromList(0, S_waveNames)// Get name of the wave created by LoadWaveWave w = $name// Create a wave referenceVariable numRows = DimSize(w, 0)Variable numColumns = DimSize(w, 1)Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
It still is not working, I keep getting an error message that states: while executing LoadWave: no data was found in file.
Function Loadtimeaxis (cwl)Variable cwl
NewPath/O dataFolder //dialog box to get the data folder pathString callist=ListFilesofType("dataFolder",1,".txt")String timefile=StringFromList(0,callist)LoadWave/G/M/P=datafolder timefile
String name = StringFromList(0,timefile)// Get name of the wave created by LoadWaveWave w = $name// Create a wave referenceVariable numRows = DimSize(w, 0)Variable numColumns = DimSize(w, 1)Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
End
I keep getting an error message that states: while executing LoadWave: no data was found in file.
Although my web browser makes it look like your file contains numbers in columns, in fact, it contains one long row of number separated by tabs.
You can't use LoadWave/G for this data. To understand why, execute this:
DisplayHelpTopic"Loading General Text Files"
You can use LoadWave/J (Load Delimited Text). Here is a function that may get you started in the right direction:
Menu"Load Waves"// Add to Load Waves submenu"Load Time File...", LoadTimeFile("", "")EndFunction LoadTimeFile(pathName, fileName)String pathName // Name of an Igor symbolic path or ""String fileName // Name of file or full path to file// First get a valid reference to a file.if((strlen(pathName)==0)||(strlen(fileName)==0))// Display dialog looking for file.Variable refNum
String filters = "Text Files (*.txt):.txt;"
filters += "All Files:.*;"Open/D/R/P=$pathName/F=filters refNum as fileName
fileName = S_fileName // S_fileName is set by Open/Dif(strlen(fileName) == 0)// User cancelled?return -1endifendifLoadWave/J/M/P=$pathName/Q fileName
String listOfWaves = S_waveNames // S_waveNames is set by LoadWaveString filePath = S_path + S_fileName // S_path and S_fileName are set by LoadWaveString name = StringFromList(0, listOfWaves)Wave w = $name// Create a wave reference// Redimension as 1D waveVariable numRows = DimSize(w, 0)Variable numColumns = DimSize(w, 1)Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
Printf"Loaded wave %s from \"%s\"\r", name, filePath
return0// SuccessEnd
To clarify what a symbolic path is versus a data folder, execute these commands:
BTW, when you post Igor code, use <igor> and </igor> tags as explained at http://www.igorexchange.com/node/3221
November 18, 2016 at 03:16 pm - Permalink
November 21, 2016 at 12:50 pm - Permalink
Although my web browser makes it look like your file contains numbers in columns, in fact, it contains one long row of number separated by tabs.
You can't use LoadWave/G for this data. To understand why, execute this:
You can use LoadWave/J (Load Delimited Text). Here is a function that may get you started in the right direction:
To clarify what a symbolic path is versus a data folder, execute these commands:
November 21, 2016 at 01:41 pm - Permalink