Matlab sensing the dynamic data changes and automatically plotting
4 次查看(过去 30 天)
显示 更早的评论
Hello guys,
This is my plot. In the plot, you can see 6 periods where big dynamic data changes happened. I don't want an overall normal conventional plot.
I want the Matlab to sense these 6 periods and generate 6 plots.
load = 'newdata3.csv';
data = readtable(load);
data = sortrows(data,'Var1','ascend');
timetable(data.Var1, data.Var2);
plot(data.Var1,data.Var2)
j1 = find(diff([0; data.Var2]) > 10);
ss = data(j1,:);
plot(ss.Var1,ss.Var2)
This is the plot I got after using your code. But I want to generate 6 plots. Can you help me?
0 个评论
采纳的回答
Star Strider
2022-11-2
Just the code this time —
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1175778/newdata3.csv');
data.Var1.Format = 'HH:mm:ss.SSS'
TS = sortrows(data,1);
TS.Var1 = TS.Var1 + 0.001*seconds(0:size(TS,1)-1).';
[envh,envl] = envelope(TS.Var2, 130, 'peaks');
% figure
% plot(TS{:,1}, TS{:,2})
% grid
% xlabel('x')
% ylabel('y')
% xline(TS.Var1(1,1)+seconds(0:60:3600))
% xline(TS.Var1(1,1)+seconds(0:300:3600),'-r', 'LineWidth',2)
figure
plot(TS{:,1}, TS{:,2}, 'DisplayName','Data')
hold on
plot(TS{:,1}, envh, '-r', 'DisplayName','Upper Envelope')
plot(TS{:,1}, envl, '-g', 'DisplayName','Lower Envelope')
hold off
grid
xlabel('x')
ylabel('y')
legend('Location','best')
figure
plot(TS{:,1}, TS{:,2}, 'DisplayName','Data')
hold on
plot(TS{:,1}, envh, '-r', 'DisplayName','Upper Envelope')
plot(TS{:,1}, envl, '-g', 'DisplayName','Lower Envelope')
grid
xlabel('x')
ylabel('y')
legend('Location','best')
% xline(TS.Var1(1,1)+seconds(0:60:3600))
% xline(TS.Var1(1,1)+seconds(0:300:3600),'-r', 'LineWidth',2)
xlim([TS.Var1(1,1) TS.Var1(9600,1)])
Lv = envh > 30 & envl < -30;
stidx = strfind([false; Lv].', [0 1])-1;
enidx = strfind([false; Lv].', [1 0]);
s = enidx - stidx;
for k = 1:numel(s)
ixr = stidx(k):enidx(k);
T{k} = TS{ixr,1};
S{k} = TS{ixr,2};
end
figure
hold on
for k = 1:numel(T)
plot(T{k}, S{k})
end
hold off
xlabel('x')
ylabel('y')
.
10 个评论
Star Strider
2022-11-3
As always, my pleasure!
I worked for about an hour to do something with that last file, and could not.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!