フィルターのクリア

read a range of values using dlmread

2 ビュー (過去 30 日間)
Costanzo
Costanzo 2012 年 10 月 15 日
回答済み: Supreeth Subbaraya 2014 年 8 月 4 日
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

回答 (1 件)

Supreeth Subbaraya
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').
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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by