フィルターのクリア

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

1 回表示 (過去 30 日間)
Adam Kubica
Adam Kubica 2022 年 12 月 16 日
編集済み: Bora Eryilmaz 2022 年 12 月 17 日
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 Center および File ExchangeSpecifying 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