Loop to compare values from the table

8 views (last 30 days)
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 Comments
dpb
dpb on 6 Apr 2020
"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 on 24 Apr 2020
Thank you very much for your answers.

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!