Assign a numerical value based on the value of a string.
Show older comments
I have data which contains a series of text strings. I have read this in from a CSV file.
The data can be thought of as "Good", "Better", "Best". I want to assign a numerical value to these so I can do some quantitative analysis.
I thought a good first step would be to create a vector with ['Good'; 'Better'; 'Best';] in and then a vector which is [1;2;3].
For each given isntance of "Good" in the data I could lookup the row ID in the first vector and then match to the row ID in the second vector.
But this feels clunky and in any case it seems you cannot put different length strings into each row of a vector - it returns
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
1 Comment
Stephen23
on 26 Sep 2023
The MATLAB approach: https://www.mathworks.com/help/matlab/categorical-arrays.html
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!