How to set bottom repeating elements in matrix to NaN?
Ältere Kommentare anzeigen
I have matrix of large size and I need to change the bottom repeating elements to nan. For instance:
a = [ 1 2 3 2 1 3
3 1 1 3 1 2
1 2 3 3 2 1
1 2 1 2 1 3
1 2 3 1 2 1];
In this matrix, I want to change the bottom repeating numbers. If the numbers are repeating on top, I don't want to do anything to them. Just want to replace the bottom repeating number by NaNs. Any help will be greatly appreciated.
Thank you.
7 Kommentare
Dyuman Joshi
am 16 Jun. 2022
Verschoben: Dyuman Joshi
am 26 Aug. 2023
Edited as per a comment
a=[1 2 3 2 1 3
3 1 1 3 1 2
1 2 3 3 2 1
1 2 1 2 1 3
1 2 3 1 2 1];
for j=1:2
for i=2:size(a,1)
if any(a(1:i-1,j)==a(i,j))
a(i,j)=NaN;
end
end
end
a
James Tursa
am 16 Jun. 2022
Please show complete example. Please define what a "bottom repeating number" is. What is the desired outcome for the matrix you show?
Sushil Pokharel
am 16 Jun. 2022
Sushil Pokharel
am 16 Jun. 2022
Sushil Pokharel
am 16 Jun. 2022
Verschoben: Dyuman Joshi
am 26 Aug. 2023
Dyuman Joshi
am 16 Jun. 2022
Verschoben: Dyuman Joshi
am 26 Aug. 2023
Okay. Just a note - If you want a general answer, do mention information explicitly. Answers will always be tailored according to the information you give. So limited data results in particular answer rather than a general solution.
I could only understand what you want to obtain after you gave another example above. Nonetheless, you got your answer.
Sushil Pokharel
am 16 Jun. 2022
Verschoben: Dyuman Joshi
am 26 Aug. 2023
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical 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!