MATLAB:在表列中计算标点符号 [英] MATLAB: Count punctuation marks in table columns

查看:52
本文介绍了MATLAB:在表列中计算标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找此表中的句子数量:

在此处下载表:

任何帮助将不胜感激.谢谢!

解决方案

如果我们使用我的上一个答案中的表格, t ,我们可以使用以下解决方案:

  punctuation_table = table();对于col = 1:size(t,2)column_name = sprintf('列%d的标点计数',col);punctuation_table.(column_name)= nnz(ismember(t(:,col).Variables,{'?',',',',','!'})));结尾 

这将创建一个像这样的表:

 标点符号表=1×4桌第1列的标点计数第2列的标点计数第3列的标点计数______________________________ ______________________________ ______________________________ ______________________________2 0 2 0 

I'm trying to find the amount of sentences in this table:

Download Table here: http://www.mediafire.com/file/m81vtdo6bdd7bw8/Table_RandomInfoMiddle.mat/file

As you can see by the full-stops, there is one sentence in column one, and 2 sentences in column 3. At the end of the day I desire to have a table with nothing but punctuation marks(with the exception of place holders like "", to keep the table rows the same length) that indicate the end of a sentence(Like "." or "?" or "!"), in order to calculate the total number of punctuation marks of each column. This is my code(Yet unsuccessful):

EqualCoumns = [2:2:max(width(Table_RandomInfoMiddle))];
for t=EqualCoumns
MiddleOnlySentenceIndicators = Table_RandomInfoMiddle((Table_RandomInfoMiddle{:, t}=='punctuation'),:);
%Reomve all but "!.?" = Which is the only sentence enders
    MiddleOnlySentenceIndicators(MiddleOnlySentenceIndicators{:, t} == ',', :) = [];
    MiddleOnlySentenceIndicators(MiddleOnlySentenceIndicators{:, t} == ';', :) = [];
    MiddleOnlySentenceIndicators(MiddleOnlySentenceIndicators{:, t} == ':', :) = [];
    MiddleOnlySentenceIndicators(MiddleOnlySentenceIndicators{:, t} == '-', :) = [];
MiddleSentence_Nr(t) =  height(MiddleOnlySentenceIndicators);
end

Right now this is almost giving good results, there is a little mistake somewhere. (In the answer I would like to request only one thing, that I might have access to the results in the same table like form, it should look something like this(edited):

Any help will be appreciated. Thank you!

解决方案

If we use the table from my previous answer, t, we can use the following solution:

punctuation_table = table();
for col=1:size(t,2)
    column_name = sprintf('Punctuation count for column %d',col);
    punctuation_table.(column_name) = nnz(ismember(t(:,col).Variables,{'?',',','.','!'}));
end

which will create a table like this:

punctuation_table =

1×4 table

Punctuation count for column 1    Punctuation count for column 2    Punctuation count for column 3    Punctuation count for column 4
______________________________    ______________________________    ______________________________    ______________________________

              2                                 0                                 2                                 0      

这篇关于MATLAB:在表列中计算标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆