MATLAB: Add value in array

addingarray

hi,
I have foldername of image, the name of image is a1.bmp, a2.bmp, b1.bmp, b2.bmp.
I want store in array when a1 & a2.bmp the value is 1, and b1&b2.bmp the value is 2.
Here the illustration :
How can I do it in matlab ? thanks

Best Answer

files = {'a1.bmp' ; 'a2.bmp' ; 'b1.bmp' ; 'b2.bmp' } ;
N = length(files) ;
iwant = zeros(N,1) ;
letter2number = @(c)1+lower(c)-'a';
for i = 1:N
[filepath,name,ext] = fileparts(files{i}) ;
k = letter2number(name) ;
iwant(i) = k(1) ;
end