read a range of values using dlmread
1 view (last 30 days)
Show older comments
Hi everybody,
I am using dlmwrite to write a vector into a .csv file. Then I would like to read only a certain range of this vector with dlmread. This is an example of my code:
% file tries.m
mins = 20; % length of recording in minutes
Fs = 512; % sample rate
a = zeros (1, mins*60*Fs); % create fake vector
dlmwrite ( 'data_raw.csv', a ); % write vector to csv file
v1 = dlmread ( 'data_raw.csv', ',', [0 0 mins*60*Fs-1 0] ); % read whole vector
v2 = dlmread ( 'data_raw.csv', ',', [1 0 mins*60*Fs-1 0] ); % read roffset = 1
When I read the whole vector (in v1) everything is fine. When I try to read starting from position 1 (in v2), I receive the following error:
Error using dlmread (line 139)
Badly formed format string.
Error in tries (line 8)
v2 = dlmread ( 'data_raw.csv', ',', [1 0 mins*60*Fs-1 0] );
Has anybody got any idea why this is happening? How can I successfully read only a range of values from the csv file?
Thank you very much, Costanzo
0 Comments
Answers (1)
Supreeth Subbaraya
on 4 Aug 2014
The "a" vector is exceeding in the number of columns a csv file can hold. You can store the vector as a column vector as opposed to a row vector in the csv and access it. To do this, write to the csv file as
>> dlmwrite('data_raw.csv',a').
Also, you can consider the function csvread for reading and writing csv files. Documentation is available here
0 Comments
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!