Error to import txt data

I want to import txt file (b_ifi_1.txt) to Matlab; my code is:
data=dataset('File','b_ifi_1.txt')
however, i have this message
Index exceeds matrix dimensions.
Error in dataset/readFile (line 123) str = strs{i}{1};
I don´t know if this dataset is so large or I have a problem about my memory o capacity configuration´
Hel me please

8 Commenti

per isakson
per isakson il 27 Set 2012
What's in b_ifi_1.txt? Does it match the default values of dataset?
Daniel
Daniel il 27 Set 2012
b_ifi_1.txt is the name of my data base that store numbers and strings; it has like 5000 rows and 1200 column; Do you believe that the size is the problem?
per isakson
per isakson il 27 Set 2012
Modificato: per isakson il 27 Set 2012
I don't think the size is the problem.
Try
dbstop if error
and check what values the variables, strs and i, hold at the line, which cause the error
I run dbstop if error; but the result was null...however, when I see the do file the problem appears in the last line of this code
% Read the values in the first line of data as strings, then try to
% convert each one to numeric.
strs = textscan(line1,repmat('%q',1,nvars),1,'delimiter',delimiter,'whitespace',whiteSpace);
format = repmat('%f',1,nvars);
for i = 1:nvars
str = strs{i}{1};
num = str2double(str);
Do you know what it means?
per isakson
per isakson il 27 Set 2012
I don't understand your question.
Did you read the page, "dataset, Class: dataset, Construct dataset array", carefully?
Could you show a few columns of the first few lines?
Tom
Tom il 27 Set 2012
Maybe strs, or strs{i} for one case is empty.
per isakson
per isakson il 27 Set 2012
Modificato: per isakson il 27 Set 2012
@Daniel, don't rely on my guesses! Show a a few columns of the first few lines of the text file!
What are the values of
  1. nvars
  2. line1
  3. strs
  4. str
  5. i
at the stop caused by dbstop?
Daniel
Daniel il 28 Set 2012
In this path is a sample of my dataset: https://www.dropbox.com/s/g88p61lrvo0p66p/b_ifi_1.txt?m
But, I have others 8 files with similar characteristics. They have 64 mb size and I wanna built up an only one file matlab

Accedi per commentare.

Risposte (1)

per isakson
per isakson il 28 Set 2012
Modificato: per isakson il 28 Set 2012
Inspection of the file, b_ifi_1.txt, shows
  1. tab-delimited
  2. plenty of "missing data"
The error you report is most likely due to "missing data" in the first row of data. DATASET uses the first data row to figure out the format. The error occurs in that part of that code.
.
--- Working code ---
Try
>> data = cssm();
>> whos data
Name Size Bytes Class Attributes
data 155x1212 1809384 dataset
where cssm.m
function dat = cssm()
file_spec = 'h:\m\cssm\b_ifi_1.txt';
%%Read the rows as strings
fid = fopen( file_spec );
cac = textscan( fid, '%s', 'BufSize', 2e4, 'Delimiter', '\n' );
sts = fclose( fid ); %#ok<*NASGU>
cac = cac{1};
%%Assert that all rows have the same number of columns
num_tab = cellfun( @(str) numel( strfind( str, char(9) ) ), cac );
assert( all( diff( num_tab ) == 0 ) ...
, 'cssm:IsRagged', 'Varying number of tabs' )
%%Read the file to a string variable and strip of the first line
str = fileread( file_spec );
ix1 = find( str==char(10), 1 , 'first' );
str = str(ix1+1:end);
%%Test parsing the string with textscan
frm = '%*s%u%u%u%u%q%u%u';
frm = cat( 2, frm, repmat( '%f', [ 1, median(num_tab) - 8 + 1 ] ) );
buf = textscan( str, frm, 'BufSize',2e4, 'Delimiter','\t' );
%%Import the file to a dataset
dat = dataset( 'File', file_spec ...
, 'Format',frm, 'BufSize',2e4, 'Delimiter','\t' );
end
and where 'h:\m\cssm\b_ifi_1.txt' is the file from dropbox

2 Commenti

Daniel
Daniel il 28 Set 2012
I've been running the recommended function, however, the first column was deleted ... what do you think is the problem? the name of this column is "FECHA" ... Additionally, I want to build a database containing more files with exactly the same characteristics (b_ifi_2, b_ifi_3, etc. ultil b_ifi_8)... in this sense, in the function that you have suggested ¿is there the possibility of adding a loop? .. can you tell me what is the procedure to do the function?..because, Iwanna try by myself
per isakson
per isakson il 28 Set 2012
Modificato: per isakson il 28 Set 2012
Since
  1. the information in the first column is duplicated by the information in the second and third column
  2. Matlab cannot use the names in the first column
I suppressed reading the first column by adding a "*" to the format string '%*s'.
You need to understand the code, which you get from a forum like this. I don't test that carefully. The function, cssm, is intended as help. You should make your own version to use in real work. You need to add some error handling for one.
Try to make something, "loop over all files", and return here if you run into problems.

Accedi per commentare.

Categorie

Richiesto:

il 27 Set 2012

Community Treasure Hunt

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

Start Hunting!

Translated by