<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507</link>
    <title>MATLAB Central Newsreader - getting the data out of Matlab fig</title>
    <description>Feed for thread: getting the data out of Matlab fig</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 20 Apr 2009 23:03:07 -0400</pubDate>
      <title>getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#644170</link>
      <author>Mahdieh </author>
      <description>I have saved 50 2D simple graphs as a Matlab .fig(s).&lt;br&gt;
Now I need to get the data out of the graphs, i.e. XY of the data points ...&lt;br&gt;
I just need to know how to get the data for one graph.&lt;br&gt;
&lt;br&gt;
Any help is appreciated, &lt;br&gt;
Thanks, &lt;br&gt;
-Mahdieh</description>
    </item>
    <item>
      <pubDate>Tue, 21 Apr 2009 00:01:21 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#644174</link>
      <author>ImageAnalyst</author>
      <description>I think it would be easier if you saved the data as .mat format files&lt;br&gt;
with the save() function instead.  Is that a possibility?  Then you&lt;br&gt;
just use the load() function and you're done - you've retrieved them.</description>
    </item>
    <item>
      <pubDate>Tue, 21 Apr 2009 00:32:02 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#644177</link>
      <author>Jiro Doke</author>
      <description>&quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gsiuva$sv8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have saved 50 2D simple graphs as a Matlab .fig(s).&lt;br&gt;
&amp;gt; Now I need to get the data out of the graphs, i.e. XY of the data points ...&lt;br&gt;
&amp;gt; I just need to know how to get the data for one graph.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any help is appreciated, &lt;br&gt;
&amp;gt; Thanks, &lt;br&gt;
&amp;gt; -Mahdieh&lt;br&gt;
&lt;br&gt;
Take a look at the documentation on &quot;Handle Graphics&quot;. The handle graphics hierarchy gives you an idea of what the parent-child relationships are in a figure.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-41259.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-41259.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
By using handles, you can traverse down to the plot objects to extract out the data.&lt;br&gt;
&lt;br&gt;
There are several ways to access that info. Here's an example, reading from &quot;test.fig&quot; which contains a line plot:&lt;br&gt;
&lt;br&gt;
fH = openfig('test.fig');  % open figure and get handle to figure&lt;br&gt;
lineH = findobj(fH, 'type', 'line');  % get handles of lines&lt;br&gt;
xData = get(lineH, 'xdata');  % get x-data&lt;br&gt;
yData = get(lineH, 'ydata');  % get y-data&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
jiro</description>
    </item>
    <item>
      <pubDate>Tue, 21 Apr 2009 00:44:01 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#644178</link>
      <author>Phil Goddard</author>
      <description>&lt;br&gt;
A .fig file is simply a .mat file with a different extension, so if you don't want to actually render the image you can do&lt;br&gt;
&amp;gt;&amp;gt; s = load('filename.fig','-mat');&lt;br&gt;
to load the data as a structure into the workspace.&lt;br&gt;
The structure follows a similar heirarchy to that of handle graphics objects so you'll need to dig into it (mainly the 'children' field of the structure, and probably down several levels) to find the XData and YData fields.&lt;br&gt;
&lt;br&gt;
Phil.</description>
    </item>
    <item>
      <pubDate>Thu, 23 Apr 2009 18:50:03 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#644997</link>
      <author>Tingyue Gu</author>
      <description>&quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gsiuva$sv8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have saved 50 2D simple graphs as a Matlab .fig(s).&lt;br&gt;
&amp;gt; Now I need to get the data out of the graphs, i.e. XY of the data points ...&lt;br&gt;
&amp;gt; I just need to know how to get the data for one graph.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any help is appreciated, &lt;br&gt;
&amp;gt; Thanks, &lt;br&gt;
&amp;gt; -Mahdieh&lt;br&gt;
&lt;br&gt;
Hello for Tingyue Gu, &lt;br&gt;
I wrote a free GUI utility called &quot;MfigExtract&quot; just to do that job. The target figure can contain multiple curves. x-axis ranges for the curves do not have to be the same! Output file is an .xls file (actually a text file with this extension) that can be opened using Excel or notepad. The data can be readily re-plotted in Excel. &lt;br&gt;
&lt;br&gt;
This utility requires MATLAB R14 or above to run. I made the source code freely available. Search the web using keywords &quot;extract x y data from matlab figure.&quot; If you cannot find it, find my home page using my name. &lt;br&gt;
&lt;br&gt;
You can also save the following lines into an m-file to run it. &lt;br&gt;
&lt;br&gt;
[filename1 pathname1]=uigetfile('*.fig','Select a figure file to extract x-y data');&lt;br&gt;
if isequal(filename1,0) | isequal(pathname1,0); return; end %User pressed Cancel&lt;br&gt;
&lt;br&gt;
[filename2, pathname2] = uiputfile('*.xls', 'Provide an Excel file name to save the x-y data');&lt;br&gt;
if isequal(filename2,0) | isequal(pathname2,0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;br&gt;
end %User pressed Cancel&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
if isempty(strfind(filename2,'.xls'));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename2=[filename2 '.xls'];&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
s = openfig(filename1); % open figure and get handle to figure&lt;br&gt;
&lt;br&gt;
%get line handles&lt;br&gt;
h = findobj(s,'Type','line');   %line is the type of your figure file.&lt;br&gt;
	if isempty(h)&lt;br&gt;
	line{1}='Your figure file does not contain x-y data.';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line{2}='Did you accidentally load a wrong file?';&lt;br&gt;
	line{3}='Your can view your figures using the File menu.';&lt;br&gt;
	line{4}='Make sure you do not load a wrong file.';&lt;br&gt;
	uiwait(msgbox(line, 'No x-y data in your file','warn'));&lt;br&gt;
	close(s)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;br&gt;
	end&lt;br&gt;
&lt;br&gt;
x=get(h,'xdata');&lt;br&gt;
y=get(h,'ydata');&lt;br&gt;
[n dummy]=size(x);  %n= number of x-y sets in the figure.&lt;br&gt;
&lt;br&gt;
fid=fopen(fullfile(pathname2,filename2), 'wt');  &lt;br&gt;
fprintf(fid,'%s %s\n', 'x, y data extracted from ', [pathname1, filename1]); &lt;br&gt;
fprintf(fid,'(A figure legend may generate extra x-y data sets with only one or two rows.)\n'); &lt;br&gt;
if n==1   %because x{i} becomes invalid symbol below if n=1 &lt;br&gt;
fprintf(fid,'%s\t %s\n', '      x1', '      y1'); &lt;br&gt;
fprintf(fid,'%g\t %g\n', [x;y]); &lt;br&gt;
elseif n &amp;gt; 1&lt;br&gt;
&lt;br&gt;
%x{1}=x1 series, y{1} is y1 series, etc.&lt;br&gt;
%find out maximum x{i} length &lt;br&gt;
maxsize=length(x{1});  &lt;br&gt;
for i=2:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if length(x{i}) &amp;gt; maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxsize=length(x{i});&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%find out whether all the x series are the same   &lt;br&gt;
xseriessame=1;&lt;br&gt;
for i=2:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isequal(x{1},x{i})==0  %0 means not equal&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xseriessame=0;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
if xseriessame==1;  %write x y1 y2... header&lt;br&gt;
fprintf(fid,'All the x series in the figure are found to be the same.\n');&lt;br&gt;
fprintf(fid,'       x\t');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'       y%g\t',i);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
fprintf(fid,'\n'); %carriage return for header line&lt;br&gt;
&lt;br&gt;
%Write each x,y pair horizontally in the output file&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j=1:maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t',x{1}(j));  %x series are the same! Write x{1} for all&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t',y{i}(j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'\n');  %carriage return at end of each row&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
elseif xseriessame==0&lt;br&gt;
&lt;br&gt;
%write x, y column header&lt;br&gt;
for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'       x%g\t        y%g\t',i,i);&lt;br&gt;
end&lt;br&gt;
fprintf(fid,'\n'); %carriage return for header line&lt;br&gt;
&lt;br&gt;
%Write each x,y pair horizontally in the output file&lt;br&gt;
for j=1:maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if j &amp;gt; length(x{i})   %the x-y pair has ended earlier than others&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'\t \t');  %mark current x, y as empty&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elseif j &amp;lt;= length(x{i})&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t %g\t',x{i}(j),y{i}(j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
fprintf(fid,'\n');  %carriage return at end of each row&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
end   %ending elseif xseriessame==0 statement&lt;br&gt;
end   %ending elseif n&amp;gt;1 statement&lt;br&gt;
&lt;br&gt;
fclose(fid);&lt;br&gt;
message{1}='Output from last run:';&lt;br&gt;
message{3}=sprintf('File = %s',filename2);&lt;br&gt;
message{5}=sprintf('Directory = %s',pathname2);&lt;br&gt;
msgbox(message,'Attention','none');&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Thu, 23 Apr 2009 19:24:01 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#645008</link>
      <author>Mahdieh </author>
      <description>awesome!&lt;br&gt;
that's what i needed.&lt;br&gt;
Thanks Jiro ...&lt;br&gt;
:)&lt;br&gt;
&lt;br&gt;
&quot;Jiro Doke&quot; &amp;lt;jiro.doke@mathworks.com&amp;gt; wrote in message &amp;lt;gsj462$af2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gsiuva$sv8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I have saved 50 2D simple graphs as a Matlab .fig(s).&lt;br&gt;
&amp;gt; &amp;gt; Now I need to get the data out of the graphs, i.e. XY of the data points ...&lt;br&gt;
&amp;gt; &amp;gt; I just need to know how to get the data for one graph.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Any help is appreciated, &lt;br&gt;
&amp;gt; &amp;gt; Thanks, &lt;br&gt;
&amp;gt; &amp;gt; -Mahdieh&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Take a look at the documentation on &quot;Handle Graphics&quot;. The handle graphics hierarchy gives you an idea of what the parent-child relationships are in a figure.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-41259.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-41259.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; By using handles, you can traverse down to the plot objects to extract out the data.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; There are several ways to access that info. Here's an example, reading from &quot;test.fig&quot; which contains a line plot:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fH = openfig('test.fig');  % open figure and get handle to figure&lt;br&gt;
&amp;gt; lineH = findobj(fH, 'type', 'line');  % get handles of lines&lt;br&gt;
&amp;gt; xData = get(lineH, 'xdata');  % get x-data&lt;br&gt;
&amp;gt; yData = get(lineH, 'ydata');  % get y-data&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope this helps.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; jiro</description>
    </item>
    <item>
      <pubDate>Tue, 28 Apr 2009 17:25:07 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#645946</link>
      <author>Tingyue Gu</author>
      <description>&quot;Tingyue Gu&quot; &amp;lt;gu@ohio.edu&amp;gt; wrote in message &amp;lt;gsqd8r$ke4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gsiuva$sv8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I have saved 50 2D simple graphs as a Matlab .fig(s).&lt;br&gt;
&amp;gt; &amp;gt; Now I need to get the data out of the graphs, i.e. XY of the data points ...&lt;br&gt;
&amp;gt; &amp;gt; I just need to know how to get the data for one graph.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Any help is appreciated, &lt;br&gt;
&amp;gt; &amp;gt; Thanks, &lt;br&gt;
&amp;gt; &amp;gt; -Mahdieh&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hello for Tingyue Gu, &lt;br&gt;
&amp;gt; I wrote a free GUI utility called &quot;MfigExtract&quot; just to do that job. The target figure can contain multiple curves. x-axis ranges for the curves do not have to be the same! Output file is an .xls file (actually a text file with this extension) that can be opened using Excel or notepad. The data can be readily re-plotted in Excel. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This utility requires MATLAB R14 or above to run. I made the source code freely available. Search the web using keywords &quot;extract x y data from matlab figure.&quot; If you cannot find it, find my home page using my name. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You can also save the following lines into an m-file to run it. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [filename1 pathname1]=uigetfile('*.fig','Select a figure file to extract x-y data');&lt;br&gt;
&amp;gt; if isequal(filename1,0) | isequal(pathname1,0); return; end %User pressed Cancel&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [filename2, pathname2] = uiputfile('*.xls', 'Provide an Excel file name to save the x-y data');&lt;br&gt;
&amp;gt; if isequal(filename2,0) | isequal(pathname2,0)&lt;br&gt;
&amp;gt;     return&lt;br&gt;
&amp;gt; end %User pressed Cancel&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt; if isempty(strfind(filename2,'.xls'));&lt;br&gt;
&amp;gt;     filename2=[filename2 '.xls'];&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; s = openfig(filename1); % open figure and get handle to figure&lt;br&gt;
&lt;br&gt;
s = openfig(filename1) &lt;br&gt;
should be replaced by &lt;br&gt;
s = openfig(fullfile(pathname1,filename1))&lt;br&gt;
&lt;br&gt;
Cheers!</description>
    </item>
    <item>
      <pubDate>Tue, 28 Apr 2009 18:27:01 -0400</pubDate>
      <title>Re: getting the data out of Matlab fig</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/249507#645962</link>
      <author>Tingyue Gu</author>
      <description>OK. I made minor changes. &lt;br&gt;
&lt;br&gt;
Figure legends may add some very short data columns to the output Excel file. In the code below, I removed legends before reading x, y data. You can get the GUI version of MfigExtract by searching the web using keywords &quot;how to extract x y data from MATLAB figure.&quot;&lt;br&gt;
&lt;br&gt;
Save the texts below as extract.m  and run it. &lt;br&gt;
&lt;br&gt;
[filename1 pathname1]=uigetfile('*.fig','Select a figure file to extract x-y data');&lt;br&gt;
if isequal(filename1,0) | isequal(pathname1,0); return; end %User pressed Cancel&lt;br&gt;
&lt;br&gt;
[filename2, pathname2] = uiputfile('*.xls', 'Provide an Excel file name to save the x-y data');&lt;br&gt;
if isequal(filename2,0) | isequal(pathname2,0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;br&gt;
end %User pressed Cancel&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
if isempty(strfind(filename2,'.xls'));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename2=[filename2 '.xls'];&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
s=hgload(fullfile(pathname1,filename1));   % open figure and get handle to figure&lt;br&gt;
delete(legend);  %legends add extra data to output. Remove legends&lt;br&gt;
&lt;br&gt;
%get line handles&lt;br&gt;
h = findobj(s,'Type','line'); %line is the type of your figure file.&lt;br&gt;
if isempty(h)&lt;br&gt;
line{1}='Your figure file does not contain x-y data.';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line{2}='Did you accidentally load a wrong file?';&lt;br&gt;
line{3}='Your can view your figures using the File menu.';&lt;br&gt;
line{4}='Make sure you do not load a wrong file.';&lt;br&gt;
uiwait(msgbox(line, 'No x-y data in your file','warn'));&lt;br&gt;
close(s)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
x=get(h,'xdata');&lt;br&gt;
y=get(h,'ydata');&lt;br&gt;
&lt;br&gt;
close(s) %close figure with legends removed&lt;br&gt;
s=hgload(fullfile(pathname1,filename1));  %show original figure with legends&lt;br&gt;
&lt;br&gt;
[n dummy]=size(x); %n= number of x-y sets in the figure.&lt;br&gt;
&lt;br&gt;
fid=fopen(fullfile(pathname2,filename2), 'wt'); &lt;br&gt;
fprintf(fid,'%s %s\n', 'x, y data extracted from ', [pathname1, filename1]); &lt;br&gt;
fprintf(fid,'(A figure legend may generate extra x-y data sets with only one or two rows.)\n'); &lt;br&gt;
if n==1 %because x{i} becomes invalid symbol below if n=1 &lt;br&gt;
fprintf(fid,'%s\t %s\n', ' x1', ' y1'); &lt;br&gt;
fprintf(fid,'%g\t %g\n', [x;y]); &lt;br&gt;
elseif n &amp;gt; 1&lt;br&gt;
&lt;br&gt;
%x{1}=x1 series, y{1} is y1 series, etc.&lt;br&gt;
%find out maximum x{i} length &lt;br&gt;
maxsize=length(x{1}); &lt;br&gt;
for i=2:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if length(x{i}) &amp;gt; maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxsize=length(x{i});&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%find out whether all the x series are the same &lt;br&gt;
xseriessame=1;&lt;br&gt;
for i=2:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isequal(x{1},x{i})==0 %0 means not equal&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xseriessame=0;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
if xseriessame==1; %write x y1 y2... header&lt;br&gt;
fprintf(fid,'All the x series in the figure are found to be the same.\n');&lt;br&gt;
fprintf(fid,' x\t');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,' y%g\t',i);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
fprintf(fid,'\n'); %carriage return for header line&lt;br&gt;
&lt;br&gt;
%Write each x,y pair horizontally in the output file&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j=1:maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t',x{1}(j)); %x series are the same! Write x{1} for all&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t',y{i}(j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'\n'); %carriage return at end of each row&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
elseif xseriessame==0&lt;br&gt;
&lt;br&gt;
%write x, y column header&lt;br&gt;
for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,' x%g\t y%g\t',i,i);&lt;br&gt;
end&lt;br&gt;
fprintf(fid,'\n'); %carriage return for header line&lt;br&gt;
&lt;br&gt;
%Write each x,y pair horizontally in the output file&lt;br&gt;
for j=1:maxsize&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if j &amp;gt; length(x{i}) %the x-y pair has ended earlier than others&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'\t \t'); %mark current x, y as empty&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elseif j &amp;lt;= length(x{i})&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(fid,'%g\t %g\t',x{i}(j),y{i}(j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
fprintf(fid,'\n'); %carriage return at end of each row&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
end %ending elseif xseriessame==0 statement&lt;br&gt;
end %ending elseif n&amp;gt;1 statement&lt;br&gt;
&lt;br&gt;
fclose(fid);&lt;br&gt;
message{1}='Output from last run:';&lt;br&gt;
message{3}=sprintf('File = %s',filename2);&lt;br&gt;
message{5}=sprintf('Directory = %s',pathname2);&lt;br&gt;
msgbox(message,'Attention','none');</description>
    </item>
  </channel>
</rss>

