Borrar filtros
Borrar filtros

Making a histogram from a struct

7 visualizaciones (últimos 30 días)
Lucy Davidson
Lucy Davidson el 16 de Feb. de 2020
Respondida: Joseph Cheng el 16 de Feb. de 2020
Can someone please help me make a histogram from a struct like this?, everytime i try to do it, it saids error and that the type of data i am using is wrong.

Respuestas (1)

Joseph Cheng
Joseph Cheng el 16 de Feb. de 2020
I'm not sure what the rest of your dataset looks like unless you are looking to do a histogram of 7 points. However this snippet of code should help get you on the right track of extracting out the values.
%This section is only used to gen dummy struct.
daysofweek={'Mon','Tue','Wed','Thurs','Fri','Sat','Sun'};
for ind = 1:numel(daysofweek)
eval(['Weekday.MeanDistance.' daysofweek{ind} '=randi(10e3);'])
end
%exctact items from scrut into categorical.
for ind = 1:numel(daysofweek)
MeanDistance(ind) = getfield(Weekday.MeanDistance,daysofweek{ind});
end
hist(MeanDistance)
If you have more data for each week you can then change MeanDistance into a MxN array through additional indexing through the structure. By going through and extracting out the data into an MxN array and knowing each column/row (depending on how you'll be storing the data you can then perform the histogram in either direction and then relabel the axes to be string or number.

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by