How to categorise a column vector

조회 수: 1 (최근 30일)
Lorenne
Lorenne 2018년 5월 1일
댓글: Siyu Guo 2018년 5월 1일
May i know how to categorise a given column vector into different types of vector? eg: given X=[A;A;G;K;M] and have to categorise if the first element of X is A-type or G-type or K-type into a matrix of those types ,eg: type = 'AGKM' and from the type , we have to sort in into different colors. eg: A-type is colored[0.64,0.73,1] G-type is colored[1,1,0.6] and so on
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2018년 5월 1일
Can you give an example. Show an input matrix and what is your expected output. Then it will be easy for us to understand the question.
Lorenne
Lorenne 2018년 5월 1일
It's like type = 'ABF' A-type color=[0.64,0.73,1] B-type color=[0.7,0.88,0.89] F-type color=[0.79 0.51 0.75] X = ['B';'F';'F';'A'] and you have to categorise the type to different colors

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

답변 (1개)

Siyu Guo
Siyu Guo 2018년 5월 1일
Try the "unique" function. Help it in MATLAB.
  댓글 수: 2
Lorenne
Lorenne 2018년 5월 1일
Its like a cell array that is extract from excel file with the first content in the cell, eg:'K011' in the first cell, so i used exotype{1}(1) and it gives ans = 'K'
But im not sure how to categorise all the cells with 'K' together to one type
Siyu Guo
Siyu Guo 2018년 5월 1일
I'm not sure whether the manipulation of cells has been improved. If I were you, I'd use for to iterate all the cells, extract the type of each cell. After this, I'd use a vector "type" to record the type code of each cell, like (assume the type code is of 'char' data type):
type = blanks(n); % n is the number of cell elements.
for i = 1:n
...
type(i) = extract_type_from_cell(i);
...
end
distinct_type = unique(type);
It may not be very efficient, but I think at least it should work for your task.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by