问题
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!
回答1:
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
来源:https://stackoverflow.com/questions/64763611/matlab-count-punctuation-marks-in-table-columns