check repeated values in a cell

7 visualizaciones (últimos 30 días)
NETHRAVATHI S
NETHRAVATHI S el 4 de Jun. de 2021
Respondida: Rahul el 17 de Oct. de 2024
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
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 also refer to the following MathWorks documentations to knwo more about these functions:
Hope this helps! Thanks.

Categorías

Más información sobre Functions en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by