Word Cloud (詞雲) - Matlab



今天要總結的是 Word Cloud 最后一個部分了,用 Matlab 來創建 word cloud。Matlab R2018b 已經提供 [wordcloud](https://www.mathworks.com/help/matlab/ref/wordcloud.html) 函數可以直接生成詞雲了。
##### >> Create Word Cloud via Matlab
  1. 准備文本。

不多說了,懶人繼續用上次那個 Word Cloud History.txt 的文本吧。

  1. 讀取並清洗數據文本。
%read txt as a string
text = string(fileread('C:\Users\yuki\Desktop\WordCloudHistory.txt'));
%delete puchuation
punctuationCharacters = ["." "?" "!" "," ";" ":"];
text = replace(text,punctuationCharacters," ");
%convert a string to array
words = split(join(text));
%delete the words has less than 5 characters, which are problely stop words
words(strlength(words)<5) = [];
%change all words to lowercase
words = lower(words);
  1. 計算詞頻並生成數組。
%calculate the frequencies for every word
[numOccurrences,uniqueWords] = histcounts(categorical(words));
  1. 生成 word cloud。
figure
%set properties for word cloud
wordcloud(uniqueWords,numOccurrences,'Shape', "rectangle", 'MaxDisplayWords', 200);
title("Word Cloud History")

Word Cloud Maltab


##### >> Notes
  1. Matlab 也有插件可以直接生成詞雲,操作簡單,不用編程,哈哈。

  2. 既然已經說了各種可以創建詞雲的方法,那么就順便總結一下什么方法好用方便不花錢。

Tool Easy Use Free Need Script
Python   Clear document, powerful text mining library   Yes   Yes
JavaScript   Need to extract array by own, and need to find a way to save the image   Yes   Yes
R   Clear document, powerful text mining library   Yes   Yes
Matlab   Clear document, interactive interface   No   Optional

##### >> Sample Code

download here


##### >> Related Blogs
1. [Word Cloud (詞雲) - Python](https://www.cnblogs.com/yukiwu/p/10967037.html) 2. [Word Cloud (詞雲) - JavaScript](https://www.cnblogs.com/yukiwu/p/10968816.html) 3. [Word Cloud (詞雲) - R](https://www.cnblogs.com/yukiwu/p/10969250.html)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM