Borrar filtros
Borrar filtros

Histogram wrong Classes help

2 visualizaciones (últimos 30 días)
Nina Perf
Nina Perf el 4 de Feb. de 2022
Editada: Nina Perf el 16 de Mzo. de 2022
Hi,
I need help representing data with the histogram function.
figure()
for i = 1:8
subplot(4,2,i), histogram(Data.score)
xlabel('score'), ylabel('Occurrences');
hold on
end
Thank you!

Respuesta aceptada

Voss
Voss el 4 de Feb. de 2022
Editada: Voss el 4 de Feb. de 2022
% random integers between 0 and 4; 100 rows by 8 columns
data = randi(5,100,8)-1;
% replace the zeros in columns 1 and 3 with 1's to replicate your situation:
data(data(:,1) == 0,1) = 1;
data(data(:,3) == 0,3) = 1;
% the problem: no bin for 0 when there are no 0's:
figure();
for i = 1:8
subplot(4,2,i);
histogram(data(:,i));
end
% the solution: forcing histogram to include a spot for 0 when there are no
% 0's, by specifying the histogram edges:
figure();
for i = 1:8
subplot(4,2,i);
histogram(data(:,i),(0:5)-0.5);
end
  2 comentarios
Nina Perf
Nina Perf el 4 de Feb. de 2022
Editada: Nina Perf el 4 de Feb. de 2022
Thank you for your explaination!
It works, however, in the x axis the labels are not centered with the bins. How can I do a graph bar with the x labels?
Voss
Voss el 5 de Feb. de 2022
I edited the answer shortly after posting, to get the bins centered properly. Are you referring to the latest version? They look centered ok to me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by