0

I have a problem when using cell arrays in an m-file. I create a number of cell arrays using the function given in here. What I store on each of these arrays is numerical values being read from a text file (I convert them to string before I put them into the arrays). The problem is that the some numbers doesn't seem to be strored in the arrays correctly:

The text file contains that:

1976787196
8
1976945848
8
1977105448
8

And the contents of a cell array in which the above is store are the following:

  Columns 1 through 3

                1976787196           681405151445000                1976945848

  Columns 4 through 6

           685476780441608                1977105448           685476780441608

As you can see, instead of stroring 8, I get a very big integer.

Actually, I want all the contents of the cell arrays that I create to contain only 32-bit integers. Can I specify that requirement somehow? Thanks in advance!

Community
  • 1
  • 1
limp
  • 889
  • 2
  • 14
  • 22

1 Answers1

0

It depends how you read the data from text file. Try using TEXTSCAN function. Format string '%u32' specifies that you want to read unsigned 32-bit integer data.

filename = 'test.txt';
fid = fopen(filename,'r');
x = textscan(fid,'%u32','delimiter','\t','CollectOutput',1);
x = x{1};
fclose(fid);
yuk
  • 19,098
  • 13
  • 68
  • 99
  • I read the text file as a string but I then I convert each string number to double with str2double before I store it into my cell array. I ve tried not to use cell arrays but regular (multidirectional)matrices and it stores everything perfect, however, I read that cell arrays are much more efficient in terms of memory usage, that's why I would prefer to use them instead of regular matrices. I probably need to read the file as 32-bit uint data I guess...Thanks for the help. – limp Nov 21 '11 at 11:27