This repository contains a MATLAB live script for doing a quick exploratory text analysis of dream journal entries stored in a plain text file (dreams.txt).
The script:
- Loads all dream text from
dreams.txt - Cleans and normalises the text (tokenisation, stop-word removal, lemmatisation, etc.)
- Builds visualisations:
- Word cloud from raw text
- Word cloud from a bag-of-words model
- Top word frequency table and stacked plot
- Computes VADER sentiment scores to estimate the overall emotional tone of the dreams
The script is designed to run on MATLAB R2020b or later.
-
<your_live_script>.mlxMATLAB Live Script containing the code you provided (copy the.mcode into a new live script and save it with any name you like, e.g.DreamAnalysis.mlx). -
dreams.txtPlain text file containing dream entries (one or more entries, any length). This file must be in the same folder as the live script or on the MATLAB search path.
- MATLAB R2020b or later
The script uses several functions from the Text Analytics Toolbox and core MATLAB:
extractFileTexttokenizedDocumentstopWordsremoveWordsaddPartOfSpeechDetailsnormalizeWordserasePunctuationremoveStopWordsremoveShortWordsremoveLongWordsbagOfWordstopkwordswordcloudstackedplotvaderSentimentScores
Make sure the Text Analytics Toolbox is installed and licensed in your MATLAB environment.
- Place
dreams.txtin the same directory as your live script (recommended), or elsewhere on the MATLAB path. - Format:
- Plain text file (UTF-8 recommended).
- Each dream can be on:
- Its own line, or
- Multiple lines, or
- All dreams in a single block of text.
- The script assumes:
- Dates, punctuation and small words are removed later in the preprocessing step.
- Any numbers (e.g. dates like
2024-10-01) will be stripped out by a regular expression.
Example (simple) structure for dreams.txt:
I was walking through a forest made of glass. A strange light followed me.
I was back at school, but everyone spoke in riddles.
I dreamed of a city floating in the sky, full of libraries and trains.