check repeated values in a cell
Mostrar comentarios más antiguos
Hello,
I have a cell with 90 elements in it.
in that, after 7th element all values are same.
I have to limit the repeatability for 3 times only. that is each set (3 times) of repeated values have to do some particular operation.
kindly help.
Code is too lenghty to attach here. this is my cell which i mentioned about.
24
1
1
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
Respuestas (1)
Rahul
el 17 de Oct. de 2024
I understand that you wish to limit the count of repeating elemets in your cell array to a maximum of 3 and then do some operations on that cell array.
- To achieve the desired result, you can use convert the cell array to a matrix using 'cell2mat' function.
- Then you can use functions like 'unique' and 'accumarray' to find the unique elements of the array and their respective counts.
- Then using a loop, all the elements can be appended to an array with the maximum count of the repeating elements to be 3 using the function 'repmat'. Here is an example:
% I have taken 'uniqueData' as the array obtained after using the 'unique' function
% I have taken 'counts' as the array obtained after using 'accumarray' function
output = {};
for i = 1:length(uniqueData)
element = uniqueData(i);
count = counts(i);
% Append limited elements to output
output = [output, repmat({element}, 1, min(count, 3))];
end
You can check this MATLAB answer: https://www.mathworks.com/matlabcentral/answers/336500-finding-the-indices-of-duplicate-values-in-one-array
You can also refer to the following MathWorks documentations to knwo more about these functions:
Hope this helps! Thanks.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!