convert xi to i

Hello,
I have created a regression tree and I have printed the cut predictors which are the variables that were used in each branch.
It gives me a cell array like this: 'x2' 'x1' 'x1'
I need these to be converted into numerical values. Instead of 'x2' I need 2 or instead of 'x1' I need 1
How should I do this conversion?
Thank you

답변 (1개)

madhan ravi
madhan ravi 2020년 7월 26일

0 개 추천

ix = ismember(cell_array, 'x1') % strcmp()
Wanted = ix + 2 * ~ix

댓글 수: 4

madhan ravi
madhan ravi 2020년 7월 26일
Wanted = str2double(regexprep(cell_array, '\D*', ''))
Parisa Keshavarz
Parisa Keshavarz 2020년 7월 26일
Thank you so much
Parisa Keshavarz
Parisa Keshavarz 2020년 7월 26일
I have one more question, I need to have a logical matrix that has n=the number of instances and tl=number of leaves in my decision tree
I want it to be 1 if instance i is in leaf j for example and 0 otherwise. does such a function for this already exist? If not how should I do it?
madhan ravi
madhan ravi 2020년 7월 26일
That’s a new question and I don’t know how it’s related to this question.

이 질문은 마감되었습니다.

질문:

2020년 7월 26일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by