Assign a numerical value based on the value of a string.
이전 댓글 표시
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
Stephen23
2023년 9월 26일
The MATLAB approach: https://www.mathworks.com/help/matlab/categorical-arrays.html
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!