MATLAB: Elements of table equal to elements of another table

elementsequaltable

Hi all!
I have a list of stations (see .txt) and a .csv (see attached) with several data. What I need to do is scan the entire .txt and for every station, eg. Airport, to go and scan column 14 of the .csv. If the station is the same, I want to do several things, eg. extract the date (column 2) and Temperature (column 15) every time Airport appears.
I tried with eq but it doesn't work.
list1 = rdir ('C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\Obs. data 4 Keppas\');
wrfdir = 'C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\2019 run\Thess\*.csv';
stations = readtable('C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\Stations coordinates.txt');
output_path='C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\OutputSimulations';
WRF_Data = readtable('C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\2019 run\Thess\THESS_Temp.csv');
% Variables
vars={'Temperature'; 'Relative humidity'};
years = {'2015'; '2019'};
varunits={'Celsius'; '%' };
%Starting loop for all files
for i=1:size(stations,1)
for k = 1:size(WRF_Data.Station,1)
if eq(stations(i,1) , WRF_Data.Station(k,1))
KEEP TEMPERATURE OR WHATEVER...
end
end
end

Best Answer

I'm not entirely clear what the ultimate goal is but one thing for sure, you don't need a loop at all.
To keep only the rows of WRF_Data that have a station in stations AND append the rest of the station variables to these rows, it's simply:
merged = innerjoin(WRF_Data, stations, 'Keys', 'Station'); %And you don't even need the 'Keys', 'stations' although it makes the code clearer.
If you don't want all the variables in the output, you can tell innerjoin which one you want:
merged = innerjoin(WRF_Data, stations, 'LeftVariables', {'Station', 'Var1', 'Temp'}, 'RightVariables', {'Lat', 'Lon'}) %for example