Importing large binary information

Hi,
I have a text file with a large number of binary information formed into groups of 10 bits, were each group is either separated by spaces.
The data looks something like this:
0001101111 0001101111 0001101111 0001001011 0001001011 0001001011
0001101111 0001101111 0001101111 0001001011 0001001011 0001001011
0001111011 0001111011 0001111011 0001011010 0001011010 0001011010
0001111011 0001111011 0001111011 0001011010 0001011010 0001011010
.
.
.
.
No what I want to do is, to import this information into an integer array of sized (x by 10) in matlab, where the 10-bit bytes are inserted into the array in an raster fashion.
i.e. I want the bytes sequenced as follow in the text file
1 2 3 4
5 6 7 8
to be inserted into the array as
1
2
3
4
5
6
7
8
Many Thanks,
Arsalan

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 16 de Jul. de 2013
Editada: Azzi Abdelmalek el 16 de Jul. de 2013
fid = fopen('file.txt');
line1 = fgetl(fid);
res={line1};
while ischar(line1)
line1 = fgetl(fid);
if ischar(line1)
res{end+1} =line1
end
end
fclose(fid);
a=cell2mat(cellfun(@(x) cell2mat(regexp(x,' ','split')'),res,'un',0)')
%If you want the result in a cell array
a=cellstr(a)

3 comentarios

Arsalan
Arsalan el 16 de Jul. de 2013
Thanks,
works Great, would you be able to tell me how I can take each bit in each cell and place it in a single element of an array.
e.g. if I have a single cell a(1,1) that contains 10 bits, now I want to have an integer array where it has a size of 1x10
Thanks
Azzi Abdelmalek
Azzi Abdelmalek el 16 de Jul. de 2013
Editada: Azzi Abdelmalek el 16 de Jul. de 2013
res=cell2mat(a)-'0'
Arsalan
Arsalan el 16 de Jul. de 2013
thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by