Compare columns of different tables and extract value
Mostra commenti meno recenti
Hello everyone.
I want to make a loop that reads all rows of a column in my first table (Tappmax_20062100.Daily_Tappmax_Rounded) and checks when a value becomes equal to a value in a column of my second table (RR.Tappmax). When this happens, I want to extract the respective RR value of the second table (RR.RR). Eg., the 1st value of Daily_Tappmax_Rounded (10.5) is equal to the 18th row of RR.Tappmax, and I want to extract the respetive RR (1.0237). In the opposite case, I want to move on to the next row of RR.Tappmax.
This is my script so far:
data = readtable('C:\PhD\ELSTAT\Data\Keppas future run\Thess_20062100.csv');
nearestValue = 0.5;
data.Daily_Tappmax_Rounded = round(data.Daily_Tappmax/nearestValue)*nearestValue;
Tappmax_20062100 = table(data.Daily_DATE, data.Daily_Tappmax_Rounded);
Tappmax_20062100.Properties.VariableNames{1} = 'Daily_DATE'; Tappmax_20062100.Properties.VariableNames{2} = 'Daily_Tappmax_Rounded';
RR = readtable('C:\PhD\ELSTAT\Data\Keppas future run\9.2 CLIMPACT\RR assessment.xlsx');
m=1;
for i = 1: length( Tappmax_20062100.Daily_Tappmax_Rounded)
if Tappmax_20062100.Daily_Tappmax_Rounded(i) == RR.Tappmax(m)
Tappmax_20062100.RR(i) = RR.RR(m)
else
m=m+1;
end
end
What is wrong with the loop? I was expecting it to work but I cannot find the mistake behind it...
PS. R2019a
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!