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?

채택된 답변

Cedric
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
Locks
Locks 2013년 4월 7일
thanks, I get still the same error:
The expression to the left of the equals sign is not a valid target for an assignment.
I used this:
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, :) ;
Cedric
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 CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by