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

1 次查看(过去 30 天)
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;

回答(1 个)

Bora Eryilmaz
Bora Eryilmaz 2022-12-16
编辑:Bora Eryilmaz 2022-12-16
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 个评论
Adam Kubica
Adam Kubica 2022-12-16
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 2022-12-17
编辑:Bora Eryilmaz 2022-12-17
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';

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by