select certain rows of a matrix dased on which data their elements are from

2 views (last 30 days)
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?

Accepted Answer

Cedric
Cedric on 7 Apr 2013
Edited: Cedric on 7 Apr 2013
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 Comments
Locks
Locks on 7 Apr 2013
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 on 7 Apr 2013
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).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!