MATLAB: Cell of string. Vectorization on elements of string

cell arraystringvectorization

G'Day
I have as an input the cell stringCell, and I try to access to the element indexToAcces of each stringCell element. In this example indexToAcces is the same for all, but in my main code indexToAcces would be the same size of stringCell and each value could be different:
stringCell{1,1}='test1'
stringCell{2,1}='test2'
indexToAcces=5
stringCell{1,1}(indexToAcces) %returns 1; this work for one element
stringCell{:,1}(indexToAcces) %this does not work,why? ??? Bad cell reference operation.I would like it to return a cell array of :'1','2'
%%So I have to do it this way but this is not efficient at all when
%%there are many elements
for ii=1:length(stringCell)
getNum{ii}=stringCell{ii,1}(5); %works
end
I always had this issue, but used not to bother too much since the size of my cells was not too big. Unfortunately, It is not the case anymore, and my code is not efficient anymore. I spend hours trying to find a solution (forums …). So I would be really grateful if someone has an answer.
Cheers Laurent

Best Answer

stringCell{1,1}='test1' ;
stringCell{2,1}='test2';
out = cellfun(@(x) x(5),stringCell,'UniformOutput',0);
out = str2num(char(out));