MATLAB: How to read in a filename that has the form ‘testx.fts’ where x ranges from 1 to 26? I want to ask the user to input x.

fileinputMATLAB

The files I want to read in are '14Oct715Sun2_x1-1.fts'
My code at the moment reads like this:
number = input('What position number: ');
A1 = fitsread('14Oct715Sun_2_',number,'1-1.fts');
A2 = fitsread('14Oct715Sun_2_',number,'1-2.fts');
A3 = fitsread('14Oct715Sun_2_',number,'1-3.fts');
A4 = fitsread('14Oct715Sun_2_',number,'1-4.fts');
A5 = fitsread('14Oct715Sun_2_',number,'1-5.fts');
A6 = fitsread('14Oct715Sun_2_',number,'1-6.fts');
A7 = fitsread('14Oct715Sun_2_',number,'1-7.fts');
A8 = fitsread('14Oct715Sun_2_',number,'1-8.fts');
A9 = fitsread('14Oct715Sun_2_',number,'1-9.fts');
A10 = fitsread('14Oct715Sun_2_',number,'1-10.fts');
Atot = A1+A2+A3+A4+A5+A6+A7+A8+A9+A10;
But when I run it I get errors:
Error using fitsread>identifyNames (line 244)
Unknown string argument: '11'.
Error in fitsread>parseInputs (line 275)
varargin = identifyNames(varargin{:});
Error in fitsread (line 95)
parseInputs(varargin{:});
Error in Lamda (line 3)
A1 = fitsread('14Oct715Sun_2_',number,'1-1.fts');

Best Answer

Try this:
A1 = fitsread(sprintf('14Oct715Sun_2_%d1-1.fts',number));
and so for the others.
EDIT
You might also want to try something like this:
for k1 = 1:10
A{k1} = fitsread(sprintf('14Oct715Sun_2_%d1-%d.fts',number,k1));
end
All the from reading the files are now in cell array ‘A’. I have no idea what are in your .fts files, but there are several ways to get data out of the cell array to create ‘Atot’. The cell2mat function might be the best place to start.