How to judge the duplicate value of the previous loop and the current loop in the loop

조회 수: 2 (최근 30일)
a = [201101 201107 201201 201207 201301 201307 201401 201407 201501 201507]
for k = 1:2
if k =mod(k,2)==1
index =(1:5)
year = a(index)
else k = mod(k,2)==0
year = index =(2:6)
end
how can find repeat value a(index(2:5))
is any way to detect or find out the existence of these duplicate values

답변 (1개)

David Hill
David Hill 2022년 5월 4일
Not sure what you are asking. Of course there are going to be repeated values in the year rows. You need to explain better with an example.
a = [201101 201107 201201 201207 201301 201307 201401 201407 201501 201507]
for k = 1:2
if mod(k,2)==1
year(k,:) = a(1:5);
else
year(k,:) = a(2:6);
end
end
  댓글 수: 1
peter huang
peter huang 2022년 5월 5일
I mean. When I get data about the date in the department, I want to use one year and two months as the time unit of the data in the department, but when I read it, I often read the time of the previous year and two months repeatedly. I would like to ask if there is a way to detect whether this loop repeats the value of the last loop

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by