Join/Append tables and keep particular table variable if duplicate rows
이전 댓글 표시
I have a an ecxel table that is updated inside excel after being generated in MATLAB with a column of some user text comments- these comments are not always present. I would like to add new rows and often duplicate rows to this table, but the new/duplicate rows will never contain comments. In the event there is a duplicate row added for the key variables, I would like to preserve the comment from the excel file if it is present, otherwise it will remain or be created as blank.
Not sure the best approach here- my various attempts at joins are not working well.
Here is an example of the excel file with comments and some new data containing duplicate rows:
excel=readtable('commented.xlsx')
load newdata.mat
newdata
The answer would look like this- all new rows from newdata are addded, but when there are duplicate Date/Time that have a comment, that comment is preserved, ('20220915' '042702' would keep the 'Windy Day' comment) Otherwise, the Comment variable is an empty char cell.
load answer
answer
댓글 수: 4
What exactly is your question? Do you want the output to be:
...
{'20220915'} {'042702'} -0.7 {'Windy Day'}
{'20220915'} {'170959'} 0.2 {'Windy Day'} % Comment copied
...
You have mentioned joining the tables. You did not do this in the posted code, so the actual question might be: how to remove a duplicate row before joining tables. Please clarify this.
Marcus Glover
2023년 2월 20일
편집: Marcus Glover
2023년 2월 20일
Jan
2023년 2월 20일
@Marcus Glover: The example from your last comment is the result of a standard concatenation. But in the original question joining two tables with 6 elements does not create a table with 12 elements. So what should be removed?
Marcus Glover
2023년 2월 20일
편집: Marcus Glover
2023년 2월 20일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!