Hello, what I intend to achieve starting from an example matrix like the one that could be data:
Detect for each different layer (variable in the fourth column) the element that is most repeated from the third one.
And finally delete all the columns of those elements that in that layer do not have the value of the one that is most repeated.
- The data shown in the images in columns VAL1 and VAL2 do not match with the ones I attached but it is not important.
- When I say delete I delete those rows, the only thing that for the example in the figure I have left them as blanks just to try to explain myself better.
I have a code that I thought to do it but in the real case the matrices are very long and those loops are a bit "crappy", can it be done in a more efficient way?
M = zeros(data(end,4),1);
for k = 0 : data(end,4)
M(k+1) = mode(data(data(:,4)==k,3));
for k = 1 : size(data,1)
if data(k,3) ~= M(data(k,4)+1)
data(k,:) = NaN(1,size(data,2));
data(~any(~isnan(data), 2),:) = ;