MATLAB: Extracting data from a text for further analysis

MATLABtext file reader

Hi,
I am new to importing data from text files to MATLAB for data processing. I have experience doing this process from excel to MATLAB, however this seems a bit more tedius.
I have a text file which I need to extract the 1st line of numeral text (line 11) as the Y coordinate matrix, the second line of numerical text (line 12) as the X coordinate matrix and lines 3-7 (lines 13-17) as the Z coordinate Matrix. This data will then be plotted on a contour plot (code already completed and found below). I also need to extract the 1st line of text (line 3) to insert as the figure's title (a below).
Code:
%plotting MSI yacht 1
figure
contourf(N_X1,N_Y1,N_Z1,50,'edgecolor','none')
title(a);
colormap cool %map colour style
xlabel('Peak Period (t)');
ylabel('Heading (deg)');
c = colorbar('southoutside');
c.Label.String = ('MSI%');

Best Answer

textChar = fileread('example.txt');
textCell = strsplit(textChar,'\n')';
y = str2num(textCell{11});
x = str2num(textCell{12});
z = str2num([textCell{13:17}]);
titleStr = textCell{3};
titleStr = strrep(titleStr, 'Graph Title - ', ''); %Remove Graph Title -