Extract certain numbers from a text file.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
Karim
le 24 Juin 2022
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)
0 commentaires
GandaBerunda
le 24 Juin 2022
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!