select certain rows of a matrix dased on which data their elements are from
1 次查看(过去 30 天)
显示 更早的评论
hi,
I have a matrix with several thousand rows and seven coulmns. In column 6 of each row can be seen the date of all the elements in that specific rows. The data set consist of days strting in january and ending in december of a specific year
I would like to select just those days that lie in a specific perdiod of time, let's say from 01/03 to 31/10
I have started with this:
%create matrix with 7 columns (F,K,PC,Price,T,date,r)
data=[F,K,PC,Price,T,date,r]
%enter period you will look at
%start date:
DateString='01-Mar-2002'
StartDate=datenum(DateString)
%end date
DateString='30-Oct-2002'
EndDate=datenum(DateString)
data=data(data(:,6)>=StartDate &...
data(:,6)=<EndDate)
the first comand creates the matrix which consists of 7 column. now basied on the start and end date entry, I would like to delete all the rows where the value of column 6 lies not in between 01 March and 30 October and save that new dataset under the name data
Unfortunately my code is not working and gives me this error: EDU>> create_dataset Error: File: create_dataset.m Line: 20 Column: 10 The expression to the left of the equals sign is not a valid target for an assignment.
Is there anybode who could help me resolve that problem?
0 个评论
采纳的回答
Cedric
2013-4-7
编辑:Cedric
2013-4-7
You almost did it; the expression
data(:,6)>=StartDate & data(:,6)=<EndDate
should be ( =< is not a relational operator)
data(:,6)>=StartDate & data(:,6)<=EndDate
which generates a vector of logicals that you want to use for selecting relevant rows of data. You can use it as a logical row index, but you still have to specify the column index, e.g. for all columns:
data = data(data(:,6)>=StartDate & data(:,6)<=EndDate, :) ;
Or as a two steps process:
rlid = data(:,6)>=StartDate & data(:,6)<=EndDate ; % Row logical index.
data = data(rlid, :) ;
2 个评论
Cedric
2013-4-7
It is because you didn't correct the relational operator (you might have seen my answer between the time I first posted it and the time I updated it with this correction).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!