Loop to compare values from the table

조회 수: 8 (최근 30일)
Izabela Nowaczynska
Izabela Nowaczynska 2020년 4월 3일
댓글: Izabela Nowaczynska 2020년 4월 24일
I try to create to compare data. I have to tables and i need to compare dates (year, month and day). Each data type is in different column. I try to make a loops to compare first years, second month and for last day and if the dates in both tables are the same I want to have value from another column from one of the table (second one). The value that loop find I need in first Table (from table twl column 7). It could happens that in first table dates are repeated but I still need this values repeated.
Can you help me solve this problem?
My code :
for i = 1:nummel(t21)
for j = 1:nummel(twl)
if isequal(t21(i,15), twl(j,1))
if isequal(t21(i,16), twl(j,2))
if isequal(t21(i,17), twl(j,3))
fprintf('Found! \n')
for j
fprintf('\r\n %04d' twl(i,7))
end
end
end
end
end
  댓글 수: 5
dpb
dpb 2020년 4월 6일
"I can't decipher what in the two variables is which variable..."
Well, going back to the first, I guess I've determined that the one time data are t21(:,15:17) and the other are twl(:,1:3).
So,
dtt21=datetime(t21(:,15:17)); % datetime array for the t21 data
dttwl=datetime(twl(:,1:3)); % ditto for twl
Now
[ia,ib]=ismember(dtt21,dttw1); % find locations of matching times t21 in tw1
data=tw1(ib,7); % the matching locations column 7 data from the second
Izabela Nowaczynska
Izabela Nowaczynska 2020년 4월 24일
Thank you very much for your answers.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by