my data is in following form:
days of week date time(hrs) visitors
mon jan 2 2010 900 501
mon jan 2 2010 1000 449
mon jan 2 2010 1100 612
likewise for every day for entire year. i need to create a matrix of days of week as shown below:
A=[
mon
mon
mon
]
You could try to use
dlmread
. It can take any ASCII delimiter. I think it might suit your requirements. See here.Taking prompts from this previous question,
The days of the week are in the first cell of
data
.You could download my csvimport submission from the File Exchange. Assuming your data is tab separated, you can read it using:
The first 2 output parameters will cell arrays of strings while the last 2 will be double matrices.
If you are just getting started with (a recent version of) matlab, the easiest way is to use the 'import wizard'.
A few simple steps:
cell array
(Vectors or matrices wont work).Optionally you can click next to import and select that you want to generate the code for this procedure. However, this will likely be a bit verbose. If you just need to do it once, I would recommend this method.
Here is how I would read the tab-separated values, and parse the dates:
As for the day-of-week column, you can get it as:
this produces different days (either your data posted was simply made-up, or you have a bug in the part that generated those dates!)