Extract certain numbers from a text file.

2 次查看(过去 30 天)
Hello all,
I have a text file with a bunch of data, from which I have to extract the data for some specific values e.g. in example text file, I want to extract the power corresponding to 90000000000 Hz for all existing values. I am struggling to read the specific data using matlab. Plz help to write a matlab code to find out the specific row and extract the corresponding data.
Thanks

回答(2 个)

Karim
Karim 2022-6-24
see below for one method to do this
% read the file
MyData = readmatrix('example_txt_file.txt');
% specify frequency value of intrest
Fi = 90000000000;
% look for the specfic value in the first column
Fi_loc = MyData(:,1) == Fi;
% get the corresponding value from the secnd column
Fi_val = MyData(Fi_loc,2)
Fi_val = 21×1
-42.3780 -41.5809 -40.8609 -40.1618 -39.5092 -38.8737 -38.2632 -37.7056 -37.1746 -36.6735

GandaBerunda
GandaBerunda 2022-6-24
Hi Ankita,
You can use the readtable() function to read from the textfile into a table. After that, you can find out the rows which have the desired frequency using the equality operator, which will give you a logical array with 1's at the rows where desired frequency is present.By this stage, you would have the specific rows where the desired data is located and you can use the same to access the corresponding power.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by