Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矢量
A = [0;1;1;1;0;0;1;1;1;2;2;2;2];
我想计算相等的相邻值的数量,以便拥有这样的矩阵:
B=[0 1 1 3 0 2 1 3 2 4];
你能帮助我吗?
这是一个简短的解决方案:
J=find(diff([A(1)-1; A])); B=[A(J), diff([J; numel(A)+1])];