converting a string of variables to numbers

조회 수: 1 (최근 30일)
ektor
ektor 2012년 5월 21일
HI all I have the varible
Country
Austria
Austria
Austria
Austria
Austria
Austria
Austria
and I want to convert it to a numeric varable. Any help?
Thanks in advance
  댓글 수: 5
ektor
ektor 2012년 5월 21일
yes, thank you again
Oleg Komarov
Oleg Komarov 2012년 5월 21일
Now that I read your duplicated question: http://www.mathworks.com/matlabcentral/answers/38910-grouping-observations-with-specific-characteristics
I understand that you do NOT want to gather but sort.
Geoff already answered your question, you have to use sortrows.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 21일
Use the multi-output form of unique() to convert string variables to numeric indices.
When you have the numeric indices, use accumarray() to sum the data into a 3D table (date, country, I-value).
Either compute further things with that table or output it, skipping the 0 entries (the ones for which there was no input data)
  댓글 수: 5
Walter Roberson
Walter Roberson 2012년 5월 22일
Note: this solution is for adding together all of the values associated with a particular triple of attributes. If you only have one value for any given combination, then this approach is not appropriate, but sortrows() would be appropriate.
ektor
ektor 2012년 5월 22일
Tnank you both!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by