Differentiating between a binary column and a decimal column from dlmread data.

Hi all-
My program creates an array from dlmread data from a text file, and the file has any number of columns. Each of the columns either contains binary (ie. 10001) or decimal (ie 17.0) data. Is there a function, or an easy way I can determine which columns contain which type of data?
Thanks!

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 23 日
If you use dlmread to read your text file, and your file looks like
1001 2 4
0101 3 5
0001 5 6
a=dlmread('file.txt')
The result is
1001 2 4
101 3 5
1 5 6
Your binary numbers are modified

4 件のコメント

Wade Warren
Wade Warren 2015 年 7 月 23 日
Yah- I understand that- which is why I'm curious if there is any way to differentiate? Let me know, thanks!
don't use dlmread to read such files, you can use textscan function to read your data
fid=fopen('file.txt')
out=textscan(fid,'%s','delimiter','\n')
fclose(fid)
out=out{:}
Wade Warren
Wade Warren 2015 年 7 月 23 日
Alright- so if I use textscan, how would I differentiate the two types of data? Really appreciate your help!
If your file looks like
45 1001 2
65.3 0101 3.35
101 0011 2.65
The code
fid=fopen('file.txt')
out=textscan(fid,'%s','delimiter','\n')
fclose(fid)
out=out{:}
a=regexp(out,'[\.\d]*','match')
n=numel(a{1})
b=reshape([a{:}],n,[])'
c=regexp(b,'(1|0)+')
column=find(all(~cellfun(@isempty,c)))

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

タグ

質問済み:

2015 年 7 月 23 日

コメント済み:

2015 年 7 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by