How to find the positions of a string which occurs multiple times

I have a file which contains many scans,and for each scan there is the following line "par 1 f1:'Amplitude ' 1.270660e-001 3.178370e-003 0" I wish to find and extract the data contained in this line everytime it appears.

4 Comments

Why? If it is exactly this line, you can parse it once manually. Or is there any additional information?
Please explain the file format more explicitely: Is it a text file? ASCII or Unicode? Are the lines separated?
The file format is an ASCII,it contains 20 scans. so the first 20 lines are text lines from the first scan which include the amplitude data which i need, there is then 20 lines of numerical data and then the 20 lines of text from scan 2 and so on, there is no scan identifier though so i need to find every occurence of Amplitude and extratct this string. The lines are not seperated.
Fine. Can you post what you have done so far and explain, where the problems occurred?
I can find the string the first time it occurs in the file and extract the text required, however i am unable to get this process to go through the entire file and return every instance of 'Amplitude'. I have imported the data so i have one object which contains the numerical data and one object which contains the text, i can find the indexes of where ampliyude occurs by using the strcmpi, which returns a logic array with a 1 where the phrase occurs and a zero otherwise. I then find the indecies of these 1's by using find(X) which tells me which cells in the array contain 1's. so i have the indecies of the text data which i want to extract but i dont know how to then create an array where it picks out these indicies from the original text data

Answers (2)

use textscan(), you may also need to use fopen(), fclose().

This question is closed.

Asked:

on 30 Sep 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!