Extracting values corresponding to exact date from a table and update it in another table on a same date
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Haris Siddiqui
el 4 de Nov. de 2021
Comentada: Muhammad Haris Siddiqui
el 4 de Nov. de 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789872/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789876/image.png)
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 comentarios
Respuesta aceptada
Seth Furman
el 4 de Nov. de 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")
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!