0
votes

I'm currently working with a dataset, Data, in Matlab which is a struct object with the fields:

Data.ISIN:  char 
Data.Date:  double X x 1
Data.Price: double X x 1
Data.Rating cell   X x 1

Each ISIN (unique identifier) has variable dates, and variable number of dates. (For example, Data(1).Date is 60 x 1, while Data(2).Date is 30 x 1)

I want to identify if a specific date is present for each ISIN, and identify the row where it is present so i can get the corresponding price and rating. Is there an efficient way to do this besides using a double loop for each date and each ISIN?

Thank you in advance for any help or advice.

1
I think you should create a table with your data. You'd have one row for each ISIN/date combination. Then indexing all rows for a given date is trivial. - Cris Luengo

1 Answers

0
votes

I am not sure I completely understand your question, but this should work if you are looking for actual dates (as day/month/year) or other specific codes:

% Some data
Data(1).ISIN = '01/01/1970';                Data(1).Price = 1;
Data(2).ISIN = '01/01/1970, 01/03/1972';    Data(2).Price = 3;
Data(3).ISIN = '01/10/1975';                Data(3).Price = 5;

% Retrieve all ISINs. This is the main thing you ar looking for
ISIN = {Data.ISIN};  

% Find a given date
where = ~cellfun(@isempty , strfind(ISIN , '01/01/1970'));

% All prices at given date. 
Prices = {Data(where).Price};

disp(Prices)

[1] [3]