I have a large number of files that I need to make histograms for therefore I want to save it from the command line. For plots I usually save it in matlab using the following command:

```
figure = plot (x,y)
saveas(figure, output, 'jpg')

```

I want to do the same for histograms:

```
figure = hist(x)
saveas(figure, output, 'jpg')

```

However I get an error that says incorrect handle. I also tried `imwrite` function, the code executes but saves a blank black image. Is there a way in which I will be able to save my histograms?