フィルターのクリア

Conditional retime method in a timetable

6 ビュー (過去 30 日間)
Gabi
Gabi 2024 年 4 月 17 日
コメント済み: Voss 2024 年 4 月 18 日
Hi,
I'm looking for a way to create a conditional retime (at a fixed fequency, let's say 1 Hz) method based on the actual values of a variable Var in a timetable T.
In the time table T attached::
if Var transitions from 0 -> 1, 0 -> 2, 1 -> 2 or 2 -> 1 use method next,
if Var transitions from 1 -> 0 or 2 -> 0 use method previous.
Is there a way?
Thanks in advance.

採用された回答

Voss
Voss 2024 年 4 月 17 日
Maybe something like this:
S = load('timetable.mat');
T2 = S.T2;
dt = 1;
t = seconds(T2.Time);
N = round((t(end)-t(1))/dt)+1;
ti = linspace(t(1),t(end),N).';
Vari = zeros(N,1);
for ii = 1:numel(t)-1
Vari(ti>t(ii) & ti<=t(ii+1)) = T2.Var(ii+logical(T2.Var(ii+1)));
end
% Another way to write that loop; may be easier to understand:
%
% for ii = 1:numel(t)-1
%
% idx = ti>t(ii) & ti<=t(ii+1);
%
% if T2.Var(ii+1) == 0 % transition ends with 0
% % (i.e., 0->0, 1->0, 2->0)
%
% Vari(idx) = T2.Var(ii); % use previous
%
% else % transition ends with 1 or 2
% % (i.e., 0->1, 0->2, 1->1, 1->2, 2->1, 2->2)
%
% Vari(idx) = T2.Var(ii+1); % use next
%
% end
%
% end
T2_retimed = timetable(seconds(ti),Vari, ...
'VariableNames',T2.Properties.VariableNames);
figure
plot(T2.Time,T2.Var,T2_retimed.Time,T2_retimed.Var)
legend({'Original','Retimed'},'Location','NorthWest')
  2 件のコメント
Gabi
Gabi 2024 年 4 月 18 日
Thanks, it surely works.
Voss
Voss 2024 年 4 月 18 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by