Assigning values to a level from non-numerical arrays

Lets say I had two non-numerical arrays which had a few different but equal number of levels
example:
getlevels(price)
ans =
low med high vhigh
getlevels(acceptability)
ans =
unacc acc good vgood
and I wanted to assign values to each of these levels.
For example:
low = 1 med = 2 high = 3 vhigh = 4
unacc = 1 acc = 2 good = 3 vood = 4
so that I could compare both of these on a graph.
How would I go about doing this?

 Accepted Answer

I would do this with the ismember command:
[tf,loc] = ismember(price,{'low','med','high','vhigh'});
The first output will tell you if the value in price is in your list, and the second index will give the location in that vector.
It is also possible to do something similar with the unique command.

More Answers (0)

Categories

Asked:

on 10 Apr 2018

Answered:

on 10 Apr 2018

Community Treasure Hunt

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

Start Hunting!