'Conversion to double from cell is not possible.'
10 ビュー (過去 30 日間)
古いコメントを表示
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?
採用された回答
Stephen23
2015 年 12 月 17 日
編集済み: Stephen23
2015 年 12 月 17 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!