import .txt file and arrange data in a matrix

2 views (last 30 days)
Hi,
basically i need to import data (both strings and numeric) from a .txt file and put the data in a matrix so that i can do further mathematical and logical manipulation with them.
so the easiest way for me to import .txt file is to simnply drag and drop them into Matlab (i have hundreds of .txt file and i could not find a better way of importing all of them without giving the path and file name every time).
after dropping them into Matlab they appear on the script and from there i cannot find a way to put them in a matrix.
in Matlab after dropping, my data looks like this-
110.0535 countdown
111.0583 countdown
119.3104 Show 6
120.3132 Show 1
121.3312 Show 5
122.3574 wait10s
132.362 start Trail
133.2927 buttonPressed 8
133.6642 buttonPressed 1
134.0424 buttonPressed 2
  1 Comment
Sarah Crimi
Sarah Crimi on 19 Dec 2018
Edited: madhan ravi on 19 Dec 2018
Hello,
I would look at this question, here Walter Robertson explains how to load all files in a folder:
However, I would add a part where you put each item into a cell. This is my guess as to how you would do this:
i.e.
dinfo = dir('*.txt');
for i = 1 : length(dinfo)
thisfilename = dinfo(i).name; %just the name
thisdata = load(thisfilename); %load just this file
a{1,i} = thisdata; %Creates a cell with data info in it
end

Sign in to comment.

Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!