Code help for data extraction

1 次查看(过去 30 天)
Nakarsha
Nakarsha 2014-3-22
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!!

回答(2 个)

Gareth Thomas
Gareth Thomas 2014-3-22
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 2014-3-22
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.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by