MATLAB: Import a .txt file with numbers and words

data importimportimport filetext filetxt

I need to import a .txt file that with numbers and words. In particular I need the first two numbers next to every "POINT" and the first number after "PATH", how can I do this?
I tried to import the .txt file using "Import Data" but this operation is too slow.
Thank you.

Best Answer

Here is my updated answer using delay.txt
clear all;
fid = fopen('delay.txt','r');
data = textscan(fid, '%s', 'Delimiter', '\n'); %read all data as string
data = data{1};
for i = 1:size(data,1)
nData{i,:} = strsplit(data{i},' '); %split data whitespace
if (mod(i,2)==1) %checks if uneven/POINT or even/PATH
nnData{i,1} = str2num(cell2mat(nData{i}(2))); %get POINT 1st number
nnData{i,2} = str2num(cell2mat(nData{i}(3))); %get POINT 2nd number
else
nnData{i,3} = str2num(cell2mat(nData{i}(2))); %get PATH 1st number
end
end
nnData = cell2mat(nnData); %make double matrix / removes empty rows
fclose(fid);