How to read digits from file to matrix, no delimeter

1 view (last 30 days)
I have a data stored in below format, no delimeter and digit domain is {0,1}. With using matlab, taking the digits and storing them in martix is reaised a problem for me. I have not managed below scnerio. So, How can I take those digits and store them on matrix as told at below?
Data in File, 32 x 32 digits
00000000000000000000000000000000
00000000001111110000000000000000
...
00000010000000100001000000000000
how to store data
matrix[1, 1:32] = 00000000000000000000000000000000
matrix[2, 1:32] = 00000000001111110000000000000000
. . .
matrix[32, 1:32] = 00000010000000100001000000000000
OR
matrix[1, 1:32] = 00000000000000000000000000000000
matrix[1, 33:64] = 00000000001111110000000000000000
. . .
matrix[1, 993:1024] = 00000010000000100001000000000000
  2 Comments
Jan
Jan on 4 Jan 2014
What is the wanted type of your variable "matrix"? "00000000001111110000000000000000" looks like a string, but perhaps you mean a logical or double vector:
[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Image Analyst
Image Analyst on 4 Jan 2014
And, if double, should it be decimal or binary:
>> bin2dec('00000010000000100001000000000000')
ans =
33689600
So, do you want 33,689,600 or do you want the number 10000000100001000000000000??????

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 4 Jan 2014
Hint:
fgetl(fid) - '0'

Andrei Bobrov
Andrei Bobrov on 4 Jan 2014
f = fopen('pathyourtextfile.txt');
c = textscan(f,'%s','delimiter','\n');
fclose(f);
out=cat(1,c{:}{:});

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!