read a range of values using dlmread

4 visualizaciones (últimos 30 días)
Costanzo
Costanzo el 15 de Oct. de 2012
Respondida: Supreeth Subbaraya el 4 de Ag. de 2014
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

Respuestas (1)

Supreeth Subbaraya
Supreeth Subbaraya el 4 de Ag. de 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').
Then you can access the values as given in the documentation here.
Also, you can consider the function csvread for reading and writing csv files. Documentation is available here

Community Treasure Hunt

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

Start Hunting!

Translated by