read decimal and hex from a single file

조회 수: 2 (최근 30일)
Tiberius
Tiberius 2013년 12월 26일
댓글: Tiberius 2013년 12월 27일
Hello. I have a file with this format :
1364475492261 *8fe8041658ab056a61a13f827d6e;
1364475492981 *5fe8041640cd9f;
.
.
.
There are those types of values (first in decimal, then ' *' and then either a long hexa code or a short one - those codes have fixed lengths and are identical to those in the example above).
My question is if I can read those from the file and create a matrix with two columns and N rows, for further data processing. My main problem is the 2 data representations (dec and hexa).
Thanks for your time.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 26일
fid = fopen('YourFile.txt', 'r');
datacell = textscan(fid, '%f *%[0-9abcdef];');
fclose(fid);
col1_cell = num2cell(datacell{1});
col2_cell = datacell{2};
mat = [col1_cell, col2_cell];
Now "mat" will be an N x 2 cell array, where the first column is numeric and the second is a string. String needs to be used instead of decoding the hex to numeric form because there is no MATLAB numeric datatype that can hold 28 hex digits (14 bytes)
  댓글 수: 1
Tiberius
Tiberius 2013년 12월 27일
Hey, thanks for the tips. They really helped me construct my program. Cheers.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by