필터 지우기
필터 지우기

Same code in a loop but different plots

조회 수: 1 (최근 30일)
Youngmin
Youngmin 2022년 11월 4일
댓글: Youngmin 2022년 11월 4일
Hello world,
I am working on making plots to visualize my data, but I am not sure what is wrong with my code. I tried to draw four subplots to display when each muscle was activated by filling the color on the area between the threshold and EMG signals. Even though I used for loop, the first column data keep displaying different patterns of filling and increasing threshold. I have attached sample data and code below.
I would really appreciate any help to find out how to fix this issue.
clear;
clc;
close all;
load sample.mat;
thr = [0.0057 0.0401 0.0090 0.0216];
t = (0:length(sample)-1)/2000;
for i = 1:4;
subplot(4,1,i);
plot(t,movmean(sample(:,i),100));
hold on;
fill(t,max(movmean(sample(:,i),100),thr(i)), ...
thr(i),"LineStyle","none");
xlim([0, t(end)]);
end
  댓글 수: 2
KSSV
KSSV 2022년 11월 4일
I think code works fine. What you are expecting?
Youngmin
Youngmin 2022년 11월 4일
What I am expecting is that all four subplots look similar to each other. However, the threshold of the first plot keeps increasing unlike other subplots despite a single value and the filling area keeps reversing to over or to under the threshold. I have attached the screenshot of the plot (created by the code above) for a better understanding. Interestingly, this issue is gone when I use the area function, but I would like to use fill because the area does not allow "LineStyle - none'. Do you have any suggestions?

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2022년 11월 4일
area also supports linestyle, none.
load('sample.mat')
thr = [0.0057 0.0401 0.0090 0.0216];
t = (0:length(sample)-1)/2000;
for i = 1:4
subplot(4,1,i);
plot(t,movmean(sample(:,i),100));
hold on;
area(t,max(movmean(sample(:,i),100),thr(i)), ...
thr(i),'LineStyle','none');
xlim([0, t(end)]);
end
  댓글 수: 1
Youngmin
Youngmin 2022년 11월 4일
@KSSV Thank you for your suggestion. I would like to remove the line of threshold when the signals are not exceeding the threshold as you can see in the second plot (red solid lines are across the plot despite LineStyle, none). Is there any way to remove that line and keep the filled area only when the signal exceeds the threshold?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by