I have a graph in matlab and I want to export the data from the graph. Is it possible to export data from the figure ?
I tried hard to export. Actually, I had exported
You can export x
and y
vectors from a figure (assuming the figure is a 2D plot for a single data set) by:
h = plot(1:10);
xVec = get(h,'XData');
yVec = get(h,'YData');
If you dont have the handle but the figure is open, then you can use gcf
, gca
as the handle for the current active figure or axis.
If you have multiple data sets (lines) in the figure you can get all of the associated data by:
lines = findobj(h, 'Type', 'line'); //h is the handle to the figure
nlines = length(lines);
points = cell(nlines,2);
for i = 1:nlines
points{i,1} = get(lines(i),'XData');
points{i,2} = get(lines(i),'YData');
end