Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

importing a column of data from a text file

1 vue (au cours des 30 derniers jours)
Siddharth
Siddharth le 29 Mai 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
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?

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 29 Mai 2013
Modifié(e) : Azzi Abdelmalek le 29 Mai 2013
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 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 29 Mai 2013
Modifié(e) : Azzi Abdelmalek le 29 Mai 2013
data=dlmread('yourfilename.txt')
numbers=arrayfun(@(x) numel(num2str(x)),data(1,:))
[idx,idx]=max(numbers)
result=data(:,idx)
Azzi Abdelmalek
Azzi Abdelmalek le 29 Mai 2013
or simply
data=dlmread('yourfilename.txt')
[idx,idx]=max(data(1,:))
result=data(:,idx)

Andrei Bobrov
Andrei Bobrov le 29 Mai 2013
Modifié(e) : Andrei Bobrov le 29 Mai 2013
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)))

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by