- You have certain arrays, where 'Tall' array represents various modes of machine while '1->2','2->4' these are logical arrays which indicate whether the machine has made a transition into corresponding mode.
- The desired output is kind of a vector/array which indicates the rows in which the transition has followed a certain pattern or sequence which is referred as 'Valid Transition'
Detect changes between specific values in a tall array
3 次查看(过去 30 天)
显示 更早的评论
I need to read through a column in a tall array and detect specific transitions in values.
Let’s say I have a tall vector of integers which indicate the operating modes of a machine. I would like to identify in which lines there are transitions of mode, i.e., 1 ->2, 2 ->4, 4 ->1. The valid transitions are known in advance.
I have tried with movmax, movmin and movmean with some success, but I would like to have a more robust solution. I guess this could be done with matlab.tall.movingWindow and some kind of simple anonymous function, maybe based on diff()?
In practical terms, so that this request can be better understood, I have a tall vector like the first column shown below. I would like to add tall columns to the right marking the initial and final line of each transition.
Tall 1->2 2->4 4->1 1->4
1 0 0 0 0
1 0 0 0 0
1 1 0 0 0
2 1 0 0 0
2 0 0 0 0
2 0 1 0 0
4 0 1 1 0
1 0 0 1 0
Thanks
0 个评论
回答(1 个)
Divyanshu
2024-2-29
Hi Francisco,
I have made certain assumptions based on my understanding from the description. Here are the assumptions:
You can refer the following sample MATLAB script which gives a 'Valid' column vector with values '1' corresponding to rows which have followed the pattern:
Tall = [1;1;1;2;2;2;4;1];
One_Two = [0;0;1;1;0;0;0;0];
Two_Four = [0;0;0;0;0;1;1;0];
Four_One = [0;0;0;0;0;0;1;1];
One_Four = [1;0;0;0;0;0;1;0];
Valid = [0;0;0;0;0;0;0;0];
t = [Tall,One_Two,Two_Four,Four_One,One_Four];
for i=1:height(Tall)
% lets assume 1->2,2->4,4->1 is valid transition.
cond1 = islogical(One_Two(i));
cond2 = islogical(Two_Four(i));
cond3 = islogical(Four_One(i));
if(cond1 && cond2 && cond3)
Valid(i) = 1;
else
Valid(i) = 0;
end
end
t = [t Valid];
Moreover, I have just checked that certain transitions like '1->2, 2->4 ' are done and have not considered the order, for which you can add more conditions as per the use-case and requirement.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!