1

I have a .dat file similar to the following:

* ID=Minilog-T
* Serial Number=1328
* Study ID=Rostherne 2008
* Start Time=13-11-2008,14:23:14
* Finish Time=09-12-2009,13:01:53
* Sample Period=02:00:00
* Number of Deployments=9
* Date(dd-mm-yyyy),Time(hh:mm:ss),Celsius (°C)
13-11-2008,14:23:14,20.6
13-11-2008,16:23:14,15.3

I would like to insert the data into a cell array where I have:

dat = {'13-11-2008','14:23:14','20.6';'13-11-2008','16:23:14','15.3'};

dat = 

    '13-11-2008'    '14:23:14'    '20.6'
    '13-11-2008'    '16:23:14'    '15.3'

I have tried:

fid = fopen(...);
dat = textscan(fid,'%s%s%s','headerlines',8);

However, this imports everything into 3 separate cell arrays i.e. it does not take the same format as a matrix. How can I solve this?

1 Answer 1

4

The thing is that textscan puts each extracted column in its own cell, so a slightly different approach is required.

One possible way to do it would involve using textscan to extract the relevant lines, and then splitting each one into comma-delimited strings using regexp:

dat = textscan(fid, '%s', 'headerlines', 8, 'delimiter', '\n')
C = regexp(dat{1}, ',', 'split');
dat = vertcat(C{:})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.