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!