Eg of data:Name of dataset in my workspace is dsColShort
run_date trade_date Volume
735934 732604 100
735934 732655 200
735934 732658 50
735934 732658 100
735934 732689 400
735934 732724 600
735934 735934 700
I need to match up when column 'run_date' == 'trade_date'. I only want to show the row that matches. eg, there will be a 732604 in trade_date column that matches a separate row in run_date column but I do not want those to populate. Only if it's in the same row that they match.
any advice on what function I can use? or if I need to define any of the rows as a separate variable?
Thanks

댓글 수: 5

What type of data is it? numeric array, table, cell array?
If its a table you just write
idx=dsColShort.run_date==dsColShort.trade_date;
dsColShort(idx,1:3)
Chris H
Chris H 2019년 10월 10일
Thanks, I did that but my values are all NaN. Would that ever be caused by the code or is it likely in my dataset?
Turlough Hughes
Turlough Hughes 2019년 10월 10일
Can you upload the data as a .mat, or provide some sample code that generates your data.
Chris H
Chris H 2019년 10월 17일
Hey just figured it out. I was pulling the wrong column name for the actual volumes. Your formula :
idx=dsColShort.run_date==dsColShort.trade_date;
dsColShort(idx,1:3)
pretty much worked so thank you!
Turlough Hughes
Turlough Hughes 2019년 10월 17일
No problem :)

댓글을 달려면 로그인하십시오.

 채택된 답변

Turlough Hughes
Turlough Hughes 2019년 10월 17일
편집: Turlough Hughes 2019년 10월 17일

0 개 추천

To find the rows in your table, called dsColShort, wherein run_date and trade_date are equal you can use the following code
idx=dsColShort.run_date==dsColShort.trade_date;
We can then use this logical index to return the rows where your condition has been satisifed:
dsColShort(idx,1:3)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

질문:

2019년 10월 10일

편집:

2019년 10월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by