Effacer les filtres
Effacer les filtres

Import txt file into matlab using programically

2 vues (au cours des 30 derniers jours)
Tinkul
Tinkul le 11 Sep 2012
I have data in txt file as shown below:
ffffffffffffffffffffffffffff
ffffffffffffffffffffffffffff
01234efefabcdeffffffffffffff
ffffffffffffabcdeabcdeffffff
abcdefabcdefabcdefabcdefabcd
abcdffffffefefefefbabadededf
1234dace56778445dcfacedbebbf
abcdfedfedabce34127432ffedab
now these data i have to take in m file by importing txt file into matlab.For that what matlab code should be written.....
Thanks
  4 commentaires
Jan
Jan le 12 Sep 2012
And what is the desired output? A String or are these characters 4 Byte hex-encoded signed integers?
Tinkul
Tinkul le 12 Sep 2012
It is continuous string of digits.There is no commas,spaces etc.Output should be same as in the txt file.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 12 Sep 2012
Modifié(e) : Jan le 12 Sep 2012
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file'); end
S = fread(fid, Inf, '*char');
fclose(fid);
Or to use a Matlab function:
S = fileread(FileName);

Plus de réponses (2)

Kevin Claytor
Kevin Claytor le 11 Sep 2012
The Documentation has rather extensive help for file opening, reading and saving http://www.mathworks.com/help/techdoc/ref/f16-5702.html#f16-14492. I will direct you to a few in particular;

K
K le 11 Sep 2012
I've used the command textread really successfully with .txt files where the columns of numbers were separated by spaces or tabs. The command looked something like this:
textread('Nameoftextfile.txt','%f %f %f','headerlines',12);
Try searching for textread in the Matlab help to get details for your specific application.

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by