在struct中查找字段具有不同长度的字段

问题描述 投票:0回答:1

我目前正在使用Matlab中的数据集Data,这是一个包含以下字段的结构对象:

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

每个ISIN(唯一标识符)具有可变日期和可变日期数。 (例如,数据(1)。日期为60 x 1,而数据(2)。日期为30 x 1)

我想确定每个ISIN是否存在特定日期,并确定其存在的行,以便我可以获得相应的价格和评级。除了为每个日期和每个ISIN使用双循环之外,还有一种有效的方法吗?

提前感谢您的任何帮助或建议。

matlab
1个回答
0
投票

我不确定我是否完全理解您的问题,但如果您要查找实际日期(如日/月/年)或其他特定代码,这应该有效:

% 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]

© www.soinside.com 2019 - 2024. All rights reserved.