How to categorise a column vector
4 views (last 30 days)
Show older comments
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 Comments
Ameer Hamza
on 1 May 2018
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.
Answers (1)
Siyu Guo
on 1 May 2018
Try the "unique" function. Help it in MATLAB.
2 Comments
Siyu Guo
on 1 May 2018
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.
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!