简体   繁体   中英

How to export data from the graph in Matlab?

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 data in the past but I forgot.

Any help is highly appreciated.

Thank you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM