Matlab sensing the dynamic data changes and automatically plotting

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Star Strider
Star Strider am 2 Nov. 2022
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'
data = 126000×2 table
Var1 Var2 ____________ _______ 00:14:54.000 -3.3268 00:14:54.000 -4.1778 00:14:54.000 -4.6337 00:14:54.000 -4.729 00:14:54.000 -4.9851 00:14:54.000 -4.2736 00:14:54.000 -3.2882 00:14:54.000 -2.257 00:14:54.000 -1.5046 00:14:54.000 -1.6617 00:14:54.000 -1.4103 00:14:54.000 -2.4553 00:14:54.000 -3.3668 00:14:54.000 -4.193 00:14:54.000 -5.1044 00:14:54.000 -5.133
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 Kommentare
uzzi
uzzi am 3 Nov. 2022
Thank you very much for helping me. I am figuring it out how to understand that data itself. Your final figure looks like very much well sorted out. Thanks again for helping me.
Star Strider
Star Strider am 3 Nov. 2022
As always, my pleasure!
I worked for about an hour to do something with that last file, and could not.
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by