Loop to compare values from the table

8 次查看(过去 30 天)
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

请先登录,再进行评论。

回答(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