why 'tabulate' function does not work here. It gives an error saying undefined function.
Ashan, tabulate is in stats. Cody does not have Statistics Toolbox.
the in-build function tabulate cannot used in here.
чёрт побери, это гениально!
3 lines using sparse
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)
Recursion is so expensive...
Slower, but actually readable in 2 lines.
It works well on version R2013b. Has the cmd "unique" changed?
unique returns a sorted array
So it does! thank you! shaved 2 off my size. :^)
hist is a great function indeed.
histc would be better as this solution would fail on x = [3 3 3] for example.
test 1 answer should be [2 3 8];
very creative solution
Sorry for gaming towards the test set... should use min(x) and max(x) instead of -3 and 11.
'tabulate' function is define for inputs of type 'double'...Please check.
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!
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
When I run the 3rd test locally, the result is accepted. But inside Cody the check fails.
THIS SOLUTION IS CORRECT!!!!
The crosstab function is in the Statistics Toolbox. Cody only supports the commands in the basic MATLAB Toolbox.
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.
Back to basics 22 - Rotate a matrix
Relative ratio of "1" in binary number
Concatenate two strings
Perimeter of a semicircle
Test for balanced parentheses
Read a column of numbers and interpolate missing data
DNA N-Gram Distribution
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office