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

조회 수: 4 (최근 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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by