Please Help, How to Export Graph as Text File
redrmangus2
I was wondering if someone can help me with this. I have a plot with multiple waves and it some cases 2 different y-axes and I was wondering how to make a procedure that would export these graphs as text files so that I can import them easily into another program (Excel or KaleidaGraph).
Thanks!
save/B/G list as "OutputFile.txt" //you can replace "outputfile.txt", //add a /P flag if you want to programatically specify the path
If you have x-waves you also want to include in the file, you will need to modify the stringlist to contain the x-waves in the proper location (do you want them first or last???). If your datawaves are in various folders, the stringlist will have to be modified to contain the complete folder paths (root:folder1:wave1; root:folder2:wave2;)
May 31, 2013 at 07:11 am - Permalink
May 31, 2013 at 07:24 am - Permalink
Thank you! I don't have any x-waves to worry about. But I am a little confused with the procedure you gave me. I created a procedure in Igor, saved it at a macro, put the graph I wanted on top but i get an error highlighting "list" saying expected wave name.
May 31, 2013 at 07:46 am - Permalink
Not sure what that means but if you:
- open the procedure window and copy the following into it:
string list = tracenamelist("", ";", 1) //get list of traces plotted on y-axis of top-most graph
save/B/G list as "OutputFile.txt" //you can replace "outputfile.txt", //add a /P flag if you want to programatically specify the path
end
- then click on the graph from which you want to export the data (this is important to make it the "top graph")
- then click on the command window and execute "ExportData()" from it. Or chose it from the Macro menu. That should work.
Alternatively, just execute the two commands within the function from the command line, after having clicked on the graph
May 31, 2013 at 08:00 am - Permalink
string str1=StringFromList(0,list, ";") //first trace name
Wave w = TraceNameToWaveRef("", str1) //first trace wave reference
String DF= GetWavesDataFolder(w,1) //data folder of first trace (we are assuming all are the same)
SetDataFolder $DF //setdatafolder
Save/G/B list as "OutputFile.txt"
May 31, 2013 at 08:01 am - Permalink
when I do that, I get the error I talked about in the above post. I have verbatim that.
May 31, 2013 at 08:11 am - Permalink
What about my previous post? Make sure that the data plotted on the graph is in the current datafolder.
May 31, 2013 at 08:16 am - Permalink
If I use your update procedure I get a different Macro Execute Error Stating "expected wave name, variable name, or operation" in reference to the wave in "Wave w"
May 31, 2013 at 08:24 am - Permalink
May 31, 2013 at 08:41 am - Permalink
string list = tracenamelist("", ";", 1) //get list of traces plotted on y-axis of top-most graph
variable i
for (i=0; i<itemsinlist(list); i+=1)
string str1=StringFromList(i,list, ";") //first trace name
Wave w = TraceNameToWaveRef("", str1) //first trace wave reference
String DF= GetWavesDataFolder(w,2) //data folder of first trace (we are assuming all are the same)
list = removefromlist(StringFromList(i,list, ";"), list)
list = addlistitem(DF, list, ";", i)
endfor
save/B/G list as "OutputFile.txt" //you can replace "outputfile.txt", //add a /P flag if you want to programatically specify the path
end
May 31, 2013 at 08:51 am - Permalink
OK, so the error is gone, but as I run the macro, nothing happens. I don't know where it is being saved if it is.
May 31, 2013 at 10:06 am - Permalink
One last thing (sorry to keep perstering you), do you know how I can include the x-axis in the export? Was taht what you were talking about regarding the x-wave?
May 31, 2013 at 10:33 am - Permalink
One last thing (sorry to keep perstering you), do you know how I can include the x-axis in the export? Was taht what you were talking about regarding the x-wave?
May 31, 2013 at 10:19 am - Permalink
As to your X values question, other programs may want to have the X values listed out for them.
This function should do the trick:
String graphName // "" for top graph.
String list, traceList, traceName
Variable index = 0
list = ""
traceList = TraceNameList(graphName, ";", 1)
string tempXwavesList=""
do
traceName = StringFromList(index, traceList, ";")
if (strlen(traceName) == 0)
break
endif
Wave w = TraceNameToWaveRef(graphName, traceName)
list += GetWavesDataFolder(w,2) + ";"
Wave/Z wx= XWaveRefFromTrace(graphName, traceName )
if( !WaveExists(wx) )
// Make a temporary X wave we'll delete later
String wxn= NameOfwave(w)[0,27]+"_x"
Wave/Z wx=$wxn
if( WaveExists(wx) )
wxn= UniqueName(wxn,1,0)
endif
Duplicate/O w, $wxn
Wave wx=$wxn
Redimension/D wx // the data may be integer, but the x values may be float or double.
wx=x // enumerate X values
endif
list += GetWavesDataFolder(wx,2) + ";"
tempXwavesList += GetWavesDataFolder(wx,2) + ";"
index += 1
while(1)
if (strlen(list) > 0)
Save/O/J/W/I/B list
// dispose of temporary waves
for( index=0; index < ItemsInList(tempXwavesList); index+=1)
Wave wx= $StringFromList(index,tempXwavesList)
KillWaves/Z wx
endfor
endif
End
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
May 31, 2013 at 07:55 pm - Permalink