Help with Box plot
Afficher commentaires plus anciens
Hi I am working with some data which has three column.(Unit Name, Date, TotalData). I have to make box plot month wise. So from this data I have to extract each month and then further extract each day and plot a combined box plot for all the days of that month. I have a script which can plot it but its not dynamic. Can anyone suggest what Can I do to further improve the script.
mydate=cellfun(@(x) x(1:end-9),Date,'un',0);
temp=table(UnitName,mydate,TotalData,Software,abs_time);
temp=sortrows(temp,5);
mydata=table2cell(temp);
mydate=mydata(:,2);
uniquedate=unique(mydate);
[~,start_idx]=ismember(uniquedate,mydate);
end_idx=ones(length(start_idx),1);
for i =1:length(start_idx)
if i==length(start_idx)
end_idx(i,1)=length(mydate);
else
end_idx(i,1)=start_idx(i+1)-1;
end
end
for i=1:length(uniquedate)
day_number=day(uniquedate(i));
[~,month_name]=month(uniquedate(i));
eval(sprintf('%s%d=TotalData(start_idx(i):end_idx(i));',month_name,day_number));
Box{i,1}=sprintf('%s%d',month_name,day_number);
end
%For Box plot
Box=[jan24;jan25;jan26;jan27;jan28;jan29;jan30;jan31];
BoxFinal=[ones(size(jan24));2*ones(size(jan25));3*ones(size(jan26));4*ones(size(jan27));...
5*ones(size(jan28));6*ones(size(jan29));7*ones(size(jan30));8*ones(size(jan31))];
boxplot(Box,BoxFinal);
grid on
set(gca,'XTick',1:1:31,'fontsize',10)
set(gca,'XTickLabel',{'jan24','jan25','jan26','jan27',...
'jan28','jan29','jan30','jan31'})
xlabel('Dates')
ylabel('TotalData')
title('Jan data for Unit - UnitName , Software xyz')
So in this example I am taking jan so I am able to filter out the days of the month and further extract data for each day and make them as a variable ex: Jan24,jan25. But when it comes to box plot I have to write these dates manually as seen in the code and the steps that follow. Can please someone help how can i do it or do you have a better approach.
Réponses (0)
Catégories
En savoir plus sur Box Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!