Problem 39. Which values occur exactly three times?
Solution Stats
Problem Comments

3 Comments
why 'tabulate' function does not work here. It gives an error saying undefined function.
http://www.mathworks.in/help/stats/tabulate.html
Ashan, tabulate is in stats. Cody does not have Statistics Toolbox.
the inbuild function tabulate cannot used in here.
Solution Comments

1 Comment
чёрт побери, это гениально!

1 Comment
3 lines using sparse

1 Comment
When I run the following solution for Test Suite #1, I get a zero in my solution array. If I replace c(i) with c, I get back a 2 and 3 (no zero). What is going on that a zero shows up?
[count, val] = histcounts(categorical(vect))
val = cellfun(@str2double, val) % convert val from string to numerical
for i = 1:length(count)
if count(i) == 3
c(i) = val(i)
end
end

1 Comment
Recursion is so expensive...

1 Comment
Sorry

1 Comment
Slower, but actually readable in 2 lines.

1 Comment
It works well on version R2013b. Has the cmd "unique" changed?

2 Comments
unique returns a sorted array
So it does! thank you! shaved 2 off my size. :^)

2 Comments

1 Comment
test 1 answer should be [2 3 8];

1 Comment
very creative solution

1 Comment
Sorry for gaming towards the test set... should use min(x) and max(x) instead of 3 and 11.

1 Comment
'tabulate' function is define for inputs of type 'double'...Please check.

1 Comment
I think HIST would be more correct here than HISTC, as HIST takes bin centres as an argument, rather than bin edges.
But this is a very clever solution. I'm using min:max as bin centres, quite a bit longer!

2 Comments
used function tabulate for a solution, however I got the following error : Undefined function 'tabulate' for input arguments of type 'double'. On the other hand this works quite well at my desktop version, can anyone explain why it is so.
Tabulate is in the Statistics Toolbox. http://www.mathworks.com/help/toolbox/stats/tabulate.html

1 Comment
When I run the 3rd test locally, the result is accepted. But inside Cody the check fails.

2 Comments
THIS SOLUTION IS CORRECT!!!!
The crosstab function is in the Statistics Toolbox. Cody only supports the commands in the basic MATLAB Toolbox.

2 Comments
please check the first case in your test suite:
the correct output should be [2 3 8], since the 8 also appears exactly three times
8 is 4 times, not three.
Problem Recent Solvers4240
Suggested Problems

10905 Solvers

Find the two most distant points
1969 Solvers

First nonzero element in each column
702 Solvers

Set the array elements whose value is 13 to 0
1086 Solvers

Rounding off numbers to n decimals
1962 Solvers
More from this Author95
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!