Remove numbers during preprocessing

6 ビュー (過去 30 日間)
Rachele Franceschini
Rachele Franceschini 2022 年 9 月 30 日
コメント済み: Ergin Sezgin 2022 年 9 月 30 日
I would like to remove numbers within text. I have this function or script for the preprocessing, how I can remove all numbers?
%Create Co-occurence Network for only class1 and 0 5%
data = dataone.text;
%textdata = data.text;
data = randsample(data,100)
%data=data(1:100,1)
documents = preprocessText(data);
bag = bagOfWords(documents);
bag1 = removeInfrequentWords(bag,2);
counts = bag1.Counts;
cooccurrence = counts.'*counts;
G = graph(cooccurrence,bag1.Vocabulary,'omitselfloops');

回答 (1 件)

Ergin Sezgin
Ergin Sezgin 2022 年 9 月 30 日
Hello Rachele,
Try using the following code with your string array.
words = ["stringOne", "stringTwo", "2022", "stringThree"]
words = 1×4 string array
"stringOne" "stringTwo" "2022" "stringThree"
doubleArray = str2double(words)
doubleArray = 1×4
NaN NaN 2022 NaN
nanIdx = isnan(doubleArray)
nanIdx = 1×4 logical array
1 1 0 1
wordsArray = words(1,nanIdx)
wordsArray = 1×3 string array
"stringOne" "stringTwo" "stringThree"
Good luck
  2 件のコメント
Rachele Franceschini
Rachele Franceschini 2022 年 9 月 30 日
Thank you for your suggest, but I am not sure. I corrected my question, maybe the preprocessing function it was not clear. I tried your script, but I have had some problem of error ('The logical indices in position 2 contain a true value outside of the array bounds.') on second-to-last.
Ergin Sezgin
Ergin Sezgin 2022 年 9 月 30 日
If the issue is with a char array, its possible to remove all numbers from it, checking each element by an explicit loop or vectorization. If there are multiple char elements in a container, same method should also work after some additional steps are added. Could you please share some of the data?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by