Extract certain numbers from a text file.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Karim
el 24 de Jun. de 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 comentarios
GandaBerunda
el 24 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Data Import and Export en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!