我有一个我无法解决的问题。我有一组以行显示的数据(通常是按句子数量组织的文本)
我的句子中的文本示例:
1. Hello, world, It, is, beautiful, to, see, you, all
2. ,Wishing, you, happy, day, ahead
我正在使用 strtok
[token remain] = strtok(remain, ', ');
% token = strtrim(token);
CellArray {NumberOFCells} = token(1:end) ;
NumberOFCells= NumberOFCells+1;
我正在使用 CellArray 将令牌存储到单元格中,但是我的代码所做的是将第一句话放入单元格中,一旦它迭代到第二个句子并删除预先分配的单元格,因此它将其替换为令牌第二句。
预期产出
[ nxn ] [ nxn ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] ......
'Hello' 'world' 'It' 'is' 'beautiful' 'to' see' 'you' 'all' 'Wishing' 'you' 'happy' 'day' 'ahead'
问题是如何在不清除预填充单元格的情况下将第二个句子字符串附加到单元格中。
谢谢,期待与matlab程序员专家会面
我的代码..忽略注释行...检索到的基本上是这种形式。
[Index,Retrieved] = system(['wn ' keyword type ]);
Retrieved;
arrowSymbol = ' => ';
CommaSymbol= ', '
NumberOfSense= 'Sense ';
% let's look for the lines with '=> ' only?
senses = regexp(Retrieved, [arrowSymbol '[\w, ]*\n '], 'match');
SplitIntoCell = regexp(senses, [CommaSymbol '[\w, ]*\n'], 'match');
% now, we take out the '=> ' symbol
for i = 1:size(senses, 2)
senses{i} = senses{i}(size(arrowSymbol,2):end);
SplitIntoCell{i}= SplitIntoCell{i}(size(CommaSymbol,2): end);
% SeperateCells= senses ([1:2 ; end-1:end]);
% SplitCellContentIntoSingleRows{i}= strtok (SeperateCells, ['\n' ])
numberCommas = size(regexp(senses{i}, CommaSymbol), 2);
remain = senses{i};
RestWord= SplitIntoCell{i};
NumberOFCells=1;
for j = 2:numberCommas + 1 + 1 % 1 for a word after last comma and 1 because starts at index 2
% RemoveCellComma= regexp (Conversion,',');
% CellArray = [CellArray strsplit(remain, ', ')];
% [str,~] = regexp(remain,'[^, \t]+', 'match', 'split');
% CellArray = [CellArray str];
% [token remain] = strtok(remain, ', ');
% token = strtrim(token);
% CellArray {NumberOFCells} = token(1:end) ;
%
% % CellArray =[CellArray strsplit(remain, ', ')]
% [str, ~]= regexp(remain,'[^, \t]+', 'match', 'split');
% CellArray = [CellArray str];
% NumberOFCells= NumberOFCells+1;
[token remain] = strtok(remain, ', ');
token = strtrim(token);
CellArray {NumberOFCells} = token;
NumberOFCells= NumberOFCells+1;
检索到=
cat, true cat
=> feline, felid
=> carnivore
=> placental, placental mammal, eutherian, eutherian mammal
=> mammal, mammalian
=> vertebrate, craniate
=> chordate
=> animal, animate being, beast, brute, creature, fauna
=> organism, being
=> living thing, animate thing
=> object, physical object
=> physical entity
=> entity