
How can I filter data plotted on my UIAxes?
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Miguel Angel Rivera Elizondo
 el 21 de Feb. de 2021
  
    
    
    
    
    Respondida: Pratyush Swain
      
 el 17 de Mayo de 2024
            Hi everyone,
I´m programming a GUI on MatLab for a class of mine. The intention is to plot data read, and previously saved, from a sensor on the UIAxes. I have 3 UIAxes, each of them for one variable (Acceleration, Magnetic Field and Rates). On all 3, the X-Axe is Time. 
The noisy data displays on the UIAxes and when I flter it, it gets filtered but the noisy data disappears. 
I would like to display both the noisy and the filtered data on my UIAxes so I can compare them. 
I already tried it using a 'Filter' Button or a Slider, but it doesn´t work. The original data always gets replaced by the filtered one. 
How can I display both the unflitered and filtered at once, using either the 'Filter' Button or the Slider? Since I´m a rookie, I really have no idea how to fix it. Below you will find the codes I wrote and the file. Thank you in advance. 
The code for the plotting is:
            File =  evalin('base','File');
            Directory2 = evalin('base','Directory2');
            S = load([Directory2,File]);
            app.Accel = [S.accel];
            app.Time = [S.time];
            plot(app.UIAxes, [S.time],[S.accel]);
            S = load([Directory2,File]);
            app.Mag_field = [S.mag_field];
            app.Time = [S.time];
            plot(app.UIAxes2, [S.time],[S.mag_field]);
            app.Mag_field = S;
            S = load([Directory2,File]);
            app.Rates = [S.rates];
            app.Time = [S.time];
            plot(app.UIAxes3, [S.time],[S.rates]);
            app.Rates = S;    
The code for the 'Filter' Button is 
            windowSize = 5; 
            b = (1/windowSize)*ones(1,windowSize);
            a = 1;
            for i=1:numel(app.UIAxes.Children)
                app.UIAxes.Children(i).YData = filter(b, a, app.UIAxes.Children(i).YData);
            end
And for the Slider
                           value = event.Value;
            smoothingdata = smooth(app.Time, app.Accel, value);
            plot(app.UIAxes, app.Accel, app.Time);
            hold(app.UIAxes, "on");
            plot(app.UIAxes, app.Accel, smoothingdata);
            hold(app.UIAxes, "off");
0 comentarios
Respuestas (1)
  Pratyush Swain
      
 el 17 de Mayo de 2024
        Hi Miguel,
I understand you have issues showing filtered and unfiltered data simultaneously on your app designer's UI windows. We need to make the following modifications:
1- For the filter button:
Instead of directly modifying the "YData" of the plotted lines, create new lines for the filtered data and add them to the axes.
windowSize = 200; 
b = (1/windowSize)*ones(1,windowSize);
a = 1;
% Plot original data
plot(app.UIAxes, app.Time, app.Accel);
% Plot filtered data
filtered_data = filter(b, a, app.Accel);
hold(app.UIAxes, 'on');
plot(app.UIAxes, app.Time, filtered_data);
hold(app.UIAxes, 'off');
 2- For the Slider:
Similar to the Filter Button, create new lines for the smoothed data and add them to the axes.
value = event.Value;
smoothingdata = smooth(app.Time, app.Accel, value);
% Plot original data
plot(app.UIAxes, app.Time, app.Accel);
% Plot smoothed data
hold(app.UIAxes, 'on');
plot(app.UIAxes, app.Time, smoothingdata);
hold(app.UIAxes, 'off');
Also,earlier in the slider call back function, the axes were in the wrong order - "plot(app.UIAxes, app.Accel, app.Time)". I made the modifications in the app and tested it on sample data, here is the output:

I have attached the app designer file and sample data for your reference. For more information on appdesigner, please refer to https://www.mathworks.com/help/matlab/app-designer.html  
Hope this helps.
0 comentarios
Ver también
Categorías
				Más información sobre Startup and Shutdown en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

