Clear Filters
Clear Filters

Code help for data extraction

1 view (last 30 days)
Nakarsha
Nakarsha on 22 Mar 2014
Answered: Image Analyst on 22 Mar 2014
Need a code allowing me to input a txt file then search for data corresponding with a given number. For example, in my file there are 20 sets of data containing over 5000 different values in a set. I have the data save in the txt file in two columns. In the end I need to be able to import several different data files and then extract values at a given point. PLEASE HELP ME!!

Answers (2)

Gareth Thomas
Gareth Thomas on 22 Mar 2014
Hi Nakarsha,
There are multiple ways of doing this.
Use the Import Tool - in MATLAB, select the text file, right click, import data.
In this tool you can create a script or function (see the Import Selection on the right, click on the little arrow down), which will code the automatically for you this process. You now have a variable in MATLAB, then all you need to do is add to the atomically script what you want.
Probably you will use something like logical indexing to get the values.
In your example you will have multiple files, with data, then all you need to do is a:
a = dir
And get all the txt files, write a for loop, call the function/script you created and continue with your work.
Does this help?

Image Analyst
Image Analyst on 22 Mar 2014
The best way is to use readtable() , but that requires R2013b or later. Failing that, if you have a really old version, use csvread(), dlmread(), importdata(), fgetl() and sscanf(), textscan() or something like that.

Categories

Find more on Characters and Strings 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!