How to extract data from a shape in Matlab?

I saved different matlab graphics in a unique .fig. The figure looks like this: picture Now I would like to introduce a filter on these graphs in order to reduce noise, but, unfortunately, I lost the code that generates these signals.
Is there any way to extract the data of each signal in this figure? I tried this:

open('ttc_delay1000.fig'); h = gcf; %current figure handle axesObjs = get(h, 'Children'); %axes handles dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes objTypes = get(dataObjs, 'Type'); %type of low-level graphics object xdata = get(dataObjs, 'XData'); %data from low-level grahics objects ydata = get(dataObjs, 'YData'); 

But I am confused, and I do not know if he is acting correctly. Thanks!

+5
source share
1 answer

One liner for your problem:

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

Steps (from internal calls to external calls):

  • open the file;
  • look into it for a series of lines;
  • return data.

data{n,1} will contain the XData LineSeries n , if data{n,2} will contain the YData specified LineSeries .

If you want to smooth the lines directly in the picture, the idea will be 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'); 
+7
source

Source: https://habr.com/ru/post/1236888/


All Articles