How to export data from the graph in Matlab?

前端 未结 1 1659
盖世英雄少女心
盖世英雄少女心 2021-01-28 02:32

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

相关标签:
1条回答
  • 2021-01-28 03:19

    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
    
    0 讨论(0)
提交回复
热议问题