How can I import a file that contains text and numerical values?
Show older comments
Hi Everyone,
I need your help. I'm writing a program that must pull data from a very large file that is formatted like this:
- 1 1 10230435 3 red no no 1 5 yes
- 3 4 23423423 4 blue no yes 2 3 no
- 4 2 23433554 5 red no no 4 2 yes
- 2 5 23434234 7 green no yes 4 5 no
This is just a sample. The real data actually has 15 columns and has thousands of rows. I have tried the following ways to read the data.
if true
% s = load('Mfile.m')
% fid = fopen('Mfile.m','r')
% s = fscanf(fid,'%s')
% fid = fopen('Mfile.m','r')
% s = fscanf(fid,'%f')
% s = xlsread('Mfile.xls')
end
The load and fscanf commands give me errors. The xlsread assigns all of the text NaN values. I'm running out of ideas, so any help is greatly appreciated.
Thanks!
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 6 Aug 2013
fid=fopen('fic.txt')
out=textscan(fid,'%f %f %f %f %s %s %s %f %f %s')
fclose(fid)
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!