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 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)
end
end
Recursion is so expensive...
Sorry
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. :^)
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.
827 Solvers
7935 Solvers
Convert a vector into a number
531 Solvers
Find nearest prime number less than input number
392 Solvers
265 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!