필터 지우기
필터 지우기

Remove rows from a table if a variable with the same name in another table does not exist

조회 수: 7 (최근 30일)
Dear MATLAB experts,
I'm trying to find a way of removing rows from the table 'transaction_dates' if there is not a variable in the table 'stockprice_data' with the same "isin" as in any of the rows of the variable "isin" in the table 'transaction_dates'. I have yet not figured out how to solve this problem, but tried to come up with a solution as in the code below:
% 'transaction_dates' and 'stockprice_data' need to be aligned since 240
% columns were removed from 'stockprice_data', which correspond to many
% rows in 'transaction_dates'
for i=1:height(transaction_dates.isin)
for j=1:width(stockprice_data)
if transaction_dates.isin(i,:) ~= stockprice_data(j,:)
transaction_dates = removevars(transaction_dates
end
end
end
the code is definitely not complete and far from being right, but it's what I've got so far, as I'm quite of a beginner in the programming world.
I would really appreciate your help.
Thank you in advance.
  댓글 수: 1
Siddharth Bhutiya
Siddharth Bhutiya 2021년 9월 27일
This should be easy to do. Can you attach sample data containing both the tables? That way people can play around with it and suggest potential ways to do that instead of trying to guess and generate the data themselves based on the description.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 9월 27일
Have you tried using the Join Tables live task? This will interactively let you align two tables using key variables. Once you have the table you want, you can generate the corresponding code.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 9월 28일
Based on the comments in your code, it looked like you were trying to align tables. If so, this is worth a shot. Take a look at the venn diagrams in the app and see if one of them represents what you are trying to do.
chiefjia
chiefjia 2021년 9월 28일
Hi Cris,
thank you for your suggestion, I've tried this approach and it worked. I had to first convert the ISINs, which were listed as variables in stockprice_data, into row values of a single column named 'isin'. Then, I implemented the jointable live task and got the result.
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by