Same code in a loop but different plots

4 次查看(过去 30 天)
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 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by