delete positions from a matrix according to a given set of conditions based on matrix elements
Ältere Kommentare anzeigen
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.

Notes.
- 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?
clear;
load data;
M = zeros(data(end,4),1);
for k = 0 : data(end,4)
M(k+1) = mode(data(data(:,4)==k,3));
end
for k = 1 : size(data,1)
if data(k,3) ~= M(data(k,4)+1)
data(k,:) = NaN(1,size(data,2));
end
end
data(~any(~isnan(data), 2),:) = [];
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!