Extracting values corresponding to exact date from a table and update it in another table on a same date
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muhammad Haris Siddiqui
le 4 Nov 2021
Commenté : Muhammad Haris Siddiqui
le 4 Nov 2021
Hello,
I have two tables with different number of rows.
I want to extract the values from table "ntt" from "VarName4" column as shown below.
and paste it in column 2 of table "C" as shown below corresponding to the exact date as in table "ntt". As table "C" have other dates for which I don't have data and want to leave it blank or with zeros.
I treid to use for loop for updating a table "C"
for k = 1:height(ntt)
p = ntt{k,"Rainfallmm"};
C(p,2) = ntt{k,"VarName4"};
end
but it gives me this error
"A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, or a cell array of character vectors"
any help would be appreciated.
Thanking you in anticipation
0 commentaires
Réponse acceptée
Seth Furman
le 4 Nov 2021
1) Convert your tables to timetables
This isn't strictly necessary to answer your question, but is generally a good idea when working with tabular timestamped data.
% Example tables
Date = datetime(2021, 1, 1:10:100)';
t1 = table(Date, (1:10)')
Date = datetime(2021, 1, 1:5:100)';
t2 = table(Date)
% Convert tables to timetables
t1 = table2timetable(t1)
t2 = table2timetable(t2)
2) Take a look at the functions (join, innerjoin, and outerjoin)
I suspect that you'll want outerjoin in your case.
outerjoin(t1, t2, "Keys", "Date")
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Time Series Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!