Q: Matlab; how to extract information from a header's file (text file) I have many text files that have 35 lines of header followed by a large matrix with data of an image (that info can be ignored and do not need to read it at the moment). I want to be able to read the header lines and extract information contained on those lines. For instance the first few lines of the header are..
File Version Number: 1.0 

    Date: 06/05/2015

    Time: 10:33:44 AM
    ===========================================================
    Beam Voltage (-kV) = 13.000

    Filament (W) = 4.052

    Cond.  (-kV) = 8.885

    CenterX1 (V) = 10.7

    CenterY1 (V) = -45.9

    Objective (%) = 71.40

    OctupoleX = -0.4653

    OctupoleY = -0.1914

    Angle (deg) = 0.00

.
I would like to be able to open this text file and read the vulue of the day and time the file was created, filament power, the condenser voltage, the angle, etc.. and save these in variables or send them to a text box on a GUI program.
I have tried several things but since the values I want to extract some times are after a '=' or after a ':' or simply after a '' then I do not know how to approach this. Perhaps reading each line and look for a match of a word? 
Any help would be much appreciated.
Thanks,
Alex

A: This is not particularly difficult, and one of the ways to do it would be to parse line-by-line as you suggested. Something like this:
MAX_LINES_TO_READ = 35;

fid = fopen('input.txt');
lineCount = 0;    

dateString = '';
beamVoltage = 0;
while ~eof(fid)
    line = fgetl(fid);
    lineCount = lineCount + 1;

    %//check conditions for skipping loop body
    if isempty(line)
        continue
    elseif lineCount > MAX_LINES_TO_READ
        break
    end

    %//find headers you are interested in
    if strfind(line, 'Date')
        %//find the first location of the header separator
        idx = find(line, ':', 1);
        %//extract substring starting from 1 char after separator
        %//note: the trim is to get rid of leading/trailing whitespace
        dateString = strtrim(line(idx + 1 : end));
    elseif strfind(line, 'Beam Voltage')
        idx = find(line, '=', 1);
        beamVoltage = str2double(line(idx + 1 : end));
    end
end

fclose(fid);

