read a range of values using dlmread
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Supreeth Subbaraya
2014년 8월 4일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!