Verify a matrix value on MATLAB

前端 未结 3 1125
醉话见心
醉话见心 2021-01-22 05:41

I am using MATLAB. I have a question about how i can verify that the values of a matrix are being repeating, like this:

A=[ 2 3 2 3 2 3 2 3]

If

3条回答
  •  迷失自我
    2021-01-22 06:29

    I would like to throw in another approach. As I see when you are asking for "repetion" so maybe you want to have the same "pattern" repeated. For this it's easy to abuse the string functions.

    A=[1,2,3,4,1,2,3,4,1,2,3]
    position_repetition = strfind(A,A(1:2))
    

    I suppose you could use regexp for more complicated pattern. Like this would check for the longest pattern that is repeated:

    tmp = regexp(char(A),'(?.+)\1+','names')
    group = double(tmp.group)
    

    this should be as I understand the question - it checks if it is a repetion of the first two entries:

    A=[1,2,3,4,1,2,3,4,1,2,3,4]
    tmp = regexp(char(A),'^(?..)\1+$','names')
    AUX = ~isempty(tmp)
    

提交回复
热议问题