Filter löschen
Filter löschen

How to program a push button which will display the graphs signal filter

1 Ansicht (letzte 30 Tage)
HELLO!
I have small GUI, which will show me 4 graphs from the text file data measured by the phone's accelerometer.
I created the code for a simple moving average filter which is displayed in graphs for individual axes (acceleration in the axis X,Y,Z + speed).
However, these filters are always displayed in the graphs, but I would like to program a pushbutton to show and disappear these filters for individual graphs. Could someone please advise me how to do this?
I'm new to programming and can't figure this out, THANKS!!
Here is my code that permanently display the filter on the x-axis acceleration graph:
% signal smoothing - a moving average filter
samplesPerSec=100;
coeff=ones(1,samplesPerSec)/samplesPerSec;
avgx=filter(coeff,1,x);
fDelay = (length(coeff)-1)/57.7;
tdx=t-fDelay/86;
L2=line(tdx,avgx, 'color', 'blue', 'linewidth',2, 'parent', ax1);
L=[L1 L2]; % handle
ax1=gca;

Antworten (1)

Bora Eryilmaz
Bora Eryilmaz am 16 Dez. 2022
Bearbeitet: Bora Eryilmaz am 16 Dez. 2022
You can set the Visible property of the line object handles to 'off' to hide them. Set them off in your button callback.
x = (1:10)';
y = rand(10,1);
h = line(x,y);
c = uicontrol;
c.String = 'Hide';
c.Callback = @(s,e)hide(h);
function hide(h)
h.Visible = 'off';
end
  2 Kommentare
Adam Kubica
Adam Kubica am 16 Dez. 2022
Thanks a lot! Could I ask what the code would look like for multiple lines in individual graphs (see original image above)? The code works for the filter in the first graph, but I don't know how to program it for all the filters in the other graphs.
Bora Eryilmaz
Bora Eryilmaz am 17 Dez. 2022
Bearbeitet: Bora Eryilmaz am 17 Dez. 2022
For each line that you want to turn on/off, store their handles in a variable, similar to what you do in your code:
subplot(211)
L1 = line(1:10,rand(1,10));
subplot(212)
L2 = line(1:10,rand(1,10));
L=[L1 L2]; % handle
Then you can turn off a given line at index k using the code:
k = 2;
L(k).Visible = 'off';

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by