function [A,wl] = ms2mat(path, name)
% MS2MAT  Read multispectral/hyperspectral image from Gerbil .txt/.png combination
%   A, wl = MAT2MS(path, name) reads image data into A and center wavelengths into wl
%   A is a 3d matrix in the order row, column, wavelength
%   path is where to find the .txt file
%   name is the filename without .txt

fid = fopen([path '/' name '.txt']);
nz = fscanf(fid, '%d', 1);
path = [path '/' fscanf(fid, '%s\n', 1)];
wl = zeros(nz, 1);

for i = 1:nz
    line = fgets(fid);
    file = sscanf(line, '%s', 1);
    wl = sscanf(line, '%*s %d', 1);
    wl(i) = wl;
    A(:,:,nz-i+1) = double(imread([path '/' file]))/255.; % 16 bit -> 8 bit scale
end

fclose(fid);

end
