How can I separate the data into two groups.?
6 views (last 30 days)
How can I separate the data into two groups.
- If the first element of a column is largest number of that column, such type of columns are placed into one group.
- If the largest number is not at the first position of that column and is present as 2nd 3rd 4thor any other position of that column, then such columns are placed in one group.
I need to form two groups of this data. Screenshot of data is attached. I highlighted few coloumn's largest number.
Thanks in advance.
David Fletcher on 21 May 2021
Edited: David Fletcher on 21 May 2021
%Get index of max values in each column
%Create logical vector of max values where the max value is the first in the
%Use logical vector to index out columns for one group
%Use (not)logical vector to index out columns of the other group
More Answers (1)
Kartikay Sapra on 21 May 2021
data = [-1 -2 -1; 0 -1 0; 0 0 0]
data(data==0) = NaN
[maxVal ids] = max(data)
part_a = data(1:end,ids==1)
part_b = data(1:end,~(ids==1))
When finding the maximum, just keep the indices of non-zero values by making zeros 'NaN'. After that, NaN values dont interfere with max/min so after retrieving the indices, change NaN back to 0.