MATLAB Answers

Is it possible to assign new values which are integers to categorical array?

7 views (last 30 days)
Rohit Deshmukh
Rohit Deshmukh on 12 Mar 2020
Edited: dpb on 12 Mar 2020
I want to change the values of categorical array, so that i can create figure from plots.I want to convert the plot into figure. For which i want app.UIAxes.XLim to be numerical not categorical. For example: currently-
app.UIAxes.XLim = 1×2 categorical array -> urban freeway
I want
app.UIAxes.XLim = 1x2 Matrix 2 6
  5 Comments
Walter Roberson
Walter Roberson on 12 Mar 2020
Traditional figures support categorical rulers by the way, no need to switch to numeric, at least not for the last few years.

Sign in to comment.

Answers (2)

Ameer Hamza
Ameer Hamza on 12 Mar 2020
findgroups is one way to convert categorical array to numeric
numeric = findgroups(categorical_array);
  6 Comments
dpb
dpb on 12 Mar 2020
"but i want to convert the plot into figure"
See Walter Roberson's comment above.
If that's not the issue, then explain the reasons behind the request. Doesn't seem rational on the face of it to replace the meaningful categorical names with numbers.

Sign in to comment.


dpb
dpb on 12 Mar 2020
Edited: dpb on 12 Mar 2020
See the above comment, but if there is some reason you really, really need/want the numbers instead on the axes, then
hAx=gca;
hAx.XTickLabel=['{2}';'{6}'];
Alternatively, create the category names as numeric when create the categorical variable and those will be what shows up on the axes.

Community Treasure Hunt

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

Start Hunting!

Translated by