histogram

I have an array which want to plot its histogram. the range of values are from 0 to 7. I want to put a text for eahc x value. I am getting the following error message:
??? Error using ==> mtimes Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> hist at 78 xx = miny + binwidth*(0:x);)

5 comentarios

Oleg Komarov
Oleg Komarov el 30 de Jun. de 2011
You did not include the code which generates the error.
Paulo Silva
Paulo Silva el 30 de Jun. de 2011
Hassan wants us to use our magic balls on all his questions
Hassan
Hassan el 1 de Jul. de 2011
I used the following code:
array1(200,400)with data type int16
L=find(array1>0);
LL=array1(L);
LC={'no data','oilseed rape','wheat','bare soil','grassland','built-up','field beans','barley'};
hist(LL)
set(gca,'XTickLabel',LC)
Drew Steen
Drew Steen el 1 de Jul. de 2011
When I define array1 as
array1=rand(200,400);
I don't get an error - although the x-tick labels show up in a way that I don't think you want. There are 10 x bins by default, and you seem to have 7 categories.
Do you need to do this at the command line? If you can use PlotTools, that is an easier way to reset x tick labels
Hassan
Hassan el 1 de Jul. de 2011
Hi Drew. I think Im getting this error because of the data type which is int8 (and not int16 as I mentioned above by mistake).
No actually I used bar() to do that but wondered if I can do that using hist() as well.

Iniciar sesión para comentar.

 Respuesta aceptada

the cyclist
the cyclist el 1 de Jul. de 2011

0 votos

Because your variable "array1" is of type int16, so is variable "LL." The hist() function doesn't seem to be able to manage type int16 input. (That's why you get the error.) You could try
>> hist(double(LL))
to get the histogram.

2 comentarios

Hassan
Hassan el 1 de Jul. de 2011
yeah you are right. that fixed the error but the histogram I get as Drew mentioned above is based on 10 bins while I want only 7 bins. Maybe its better to use bar() instead.
the cyclist
the cyclist el 1 de Jul. de 2011
Since you have not include your actual data, it is difficult to know which is better, but another option is to use the second argument of the hist() function to specify the exact bin locations, which I am guessing correspond to your 7 labels.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 30 de Jun. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by