Extract certain numbers from a text file.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Karim
il 24 Giu 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 Commenti
GandaBerunda
il 24 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Data Import and Export in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!