Junxian
Junxian

Reputation: 105

Matlab: Multiply vertical axis of hist plot by a number

The hist function in matlab plots the frequency of the data points in the vertical axis. What should I do if I want to multiply the frequency by a number.

For example if an object points at North 10 times during the entire recording of data and each time, it stays in the North position for 5 seconds. Instead of having the hist plot show that the object pointed at North 10 times, I would like it to show that it pointed at North for a total of 50 seconds.

Upvotes: 1

Views: 209

Answers (1)

chthonicdaemon
chthonicdaemon

Reputation: 19830

You can use the histc (or histcounts in 2014b) function to do the bin counting without plotting the data, then plot using bar.

directions = rand(1000, 1)*360;
% note that histc counts the last element as exactly equal, so I pad
edges = [0:5:360, inf]; 
counts = histc(directions, edges);

multiplier = 5;

bar(edges(1:end-1)*multiplier, counts(1:end-1))

Upvotes: 2

Related Questions