How to extract data from figure in matlab?

做~自己de王妃 提交于 2019-12-04 08:28:10

A one-liner for your problem:

data = get(findobj(open('ttc_delay1000.fig'), 'Type','line'), {'XData','YData'});

The steps are there (from the inner calls to the outer calls):

  • open the file;
  • look into it for the line series;
  • return the data.

data{n,1} will contain the XData of the LineSeries number n, wile the data{n,2} will contain the YData of the said LineSeries.

If you want to smooth the lines directly in the figure, the idea is the same:

    %//Prepare moving average filter of size N
    N = 5;
    f = @(x) filter(ones(1,N)/N, 1, x);

    %//Smooth out the Y data of the LineSeries
    hf = open('ttc_delay1000.fig');
    for hl = transpose(findobj(hf,'Type','line'))
            set(hl, 'YData', f(get(hl,'YData')));
    end;
    saveas(hf, 'ttc_delay1000_smooth.fig');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!