MATLAB: Count how many times a certain number appears in a file. (Ouput that data so it can be read easily)

histogramoutput numberstxt

I have written a code where it reads a file and then outputs the data into a diagram. However, I would like it to output the data into a nice Index so I can read off i.e. how many times the number 1 appeared, and how many times the number 2 appeared.

Best Answer

Try histogram() or histcounts()
[counts, edges] = histcounts(data);
histObject = histogram(data);
histogram() will do plotting. With histcounts() you have to plot the counts yourself with bar() or plot().