'Conversion to double from cell is not possible.'
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ely may
el 16 de Dic. de 2015
Problem: I have this code that calculate postfix but when I use it gives me an error.
Postfix(nCols)=struct('matches',[],'postfix',[]);
for k=1:nCols
for l=1:25
% Calcolo postfissi associati alle traiettorie dei singoli utenti
if ~isempty(semanticTrajCompact(1,k).TrajCompact)
[Postfix(1,k).matches(:,l), Postfix(1,k).postfix(:,l)] = regexp(semanticTrajCompact(1,k).TrajCompact,sprintf('%d%d(.*)',digits{1}(l),digits{2}(l)),'match','once','tokens');
end
end
end
The error is:
'Conversion to double from cell is not possible.'
Can you give me some suggestions to solve it?
4 comentarios
Walter Roberson
el 17 de Dic. de 2015
Try
Postfix(nCols) = struct('matches',[],'postfix',{{}});
Respuesta aceptada
Stephen23
el 17 de Dic. de 2015
Editada: Stephen23
el 17 de Dic. de 2015
Try
tmp = repmat({{}},1,nCols);
Postfix = struct('matches',tmp,'postfix',tmp)
Your original problem is that you defined the fields values to be (empty) doubles (using 'matches',[]), and you then try to extend these doubles with cell arrays. So this is the error you are making:
>> X = [];
>> X(:,1) = {'a','b','c'}
The following error occurred converting from cell to double:
Error using double
Conversion to double from cell is not possible.
The solution is to define the field values to be empty cell arrays, which can then be extended with the output of regexp. To do this we need to read the struct documentation carefully, because the highest level of cell array is not considered to be data, but determines the size of the structure. So you need to wrap the empty cell arrays in a cell array of the size of structure that you need. This is what my code does.
This is a good lesson in actually reading the documentation, and actually checking that an operator really does what you think it does. Sadly beginners seem to think that these are both a waste of time.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!