MATLAB: Suggestions for Input type from user

inputMATLAB

I am having issues with the input from the user in a pre-defined format and converting them into required digits, that are to be checked for divisibility of 11.
Cells are used to fetch the data from user. But, the code is failing when the number of test cases are more than 1.
Error – Index exceeds the number of array elements
Could anyone advice me whats the appropriate way to store the input from user.
Elevenagram from Google Kickstart, Round H, 2019 –
It is a well known fact that a number is divisible by 11 if and only if the alternating sum of its digits is equal to 0 modulo 11. For example, 8174958 is a multiple of 11, since 8 – 1 + 7 – 4 + 9 – 5 + 8 = 22.
Given a number that consists of digits from 1-9, can you rearrange the digits to create a number that is divisible by 11?
Since the number might be quite large, you are given integers A1, A2, …, A9. There are Ai digits i in the number, for all i.
Input
The first line of the input gives the number of test cases, T. T lines follow. Each line contains the nine integers A1, A2, …, A9.
Input Example –
2 %No. of Test Cases
0 0 2 0 0 1 0 0 0 % the digits are 336
0 0 0 0 0 0 0 0 12 % the digits are 999999999999 = 9 – 12's
Code ( To Convert the user input(s) into actual number(s) only)
n = input ('Enter Test cases : ');
for i=1:n
iter{i} = input('Enter Values :\n','s');
end
for i=1:n
iter{i} = str2num(iter{i});
end
digit = {[1:9]};
% 0 3 0 0 0 0 0 0 0; 1 2 3 4 5 6 7 8 9;
% gives 222 - actual number to be checked later for divisiblity of 11
len_iter=length(iter);
len_iter_digit=length(iter{1});
len_digit = length(digit{1});
ele = zeros(1,len_digit);
for j =1: len_iter
for i = 1:len_iter_digit
ele(i) = sum( 10.^((1:iter{j}(i))-1));
ele(i) = ele(i)*digit{j}(i);
end
end

Best Answer

Your first problem can be avoided by using digit{1}(i) instead, since the numbers 1-9 don't change between values.
Then you will realize that ele will only store the last iteration. Can you see why?
After that you will notice that you have a vector, not a number. I would suggest creating the number first as a character array.
iter={[0 3 0 0 0 0 0 0 0],[1 2 3 4 5 6 7 8 9]};
ele=cell(size(iter));
digit_chars='123456789';digit_chars=num2cell(digit_chars);
for n=1:numel(iter)
tmp=digit_chars;
for digit=1:9
%now use repmat
end
%now convert the tmp variable to a char array
%(e.g. with a direct function, or by using {:} to create a comma separated list)
%finally covert the char array to a double
end