Info
此问题已关闭。 请重新打开它进行编辑或回答。
importing a column of data from a text file
1 次查看(过去 30 天)
显示 更早的评论
i need to import a particular column of data from a text file. the columns are differentiated by the size of the numbers. For example :
20 30000
21 40000
24 50000
how can i do so?
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-5-29
编辑:Azzi Abdelmalek
2013-5-29
Import the data using
data=dlmread('yourfilename.txt')
Then choose the column you want
data(:,2)
% You can get the sizes of numbers in each column
numbers=arrayfun(@(x) numel(num2str(x)),data(1,:))
3 个评论
Azzi Abdelmalek
2013-5-29
编辑:Azzi Abdelmalek
2013-5-29
data=dlmread('yourfilename.txt')
numbers=arrayfun(@(x) numel(num2str(x)),data(1,:))
[idx,idx]=max(numbers)
result=data(:,idx)
Azzi Abdelmalek
2013-5-29
or simply
data=dlmread('yourfilename.txt')
[idx,idx]=max(data(1,:))
result=data(:,idx)
Andrei Bobrov
2013-5-29
编辑:Andrei Bobrov
2013-5-29
d = dlmread('yourtxtfile.txt');
[k,k] = max(log10(d(1,:)));
out = d(:,k);
or
[k,k] = max(log10(d(:)));
out = d(:,ceil(k/size(d,1)))
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!