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?

 채택된 답변

the cyclist
the cyclist 2018년 4월 10일
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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2018년 4월 10일

답변:

2018년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by