Skip to content

Instantly share code, notes, and snippets.

@jeremywrnr
Last active August 29, 2015 14:07
Show Gist options
  • Save jeremywrnr/c967d29ccf8723b05164 to your computer and use it in GitHub Desktop.
Save jeremywrnr/c967d29ccf8723b05164 to your computer and use it in GitHub Desktop.
better living through automatic matlab figure generation
function [] = genPlots( t )
% pass in your table to plot area
% t = opennlm;
close all;
labsize = 50;
ticksize = 30;
tname = inputname(1);
xtrange = [0:100:500];
xlimrange = [-50 550];
ylimrange = [0.05 100];
ytrange = [0.1; 1; 10; 100];
ytlabel = ['0.1%'; '1.0%'; '10.%'; '100%'];
% back jumps
[histFreq, histXout] = hist(t.bjs ,xtrange);
f1 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1,'BaseValue',0.1);
xlabel('# backjumps','FontSize',labsize);
ylabel('% students', 'FontSize',labsize);
xlim(xlimrange)
ylim(ylimrange)
set(gca, 'XTick', xtrange)
set(gca, 'YTick', ytrange)
set(gca, 'Yscale', 'log')
set(gca, 'YTickLabel', ytlabel)
set(gca, 'FontSize',ticksize)
outname1 = strcat(tname,'_bjs');
% sub back jumps
[histFreq, histXout] = hist(t.sub_bjs, xtrange);
f2 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1,'BaseValue',0.1);
xlabel('# sub-backjumps','FontSize',labsize);
ylabel('% students', 'FontSize',labsize);
xlim(xlimrange)
ylim(ylimrange)
set(gca, 'Yscale', 'log')
set(gca, 'XTick', xtrange)
set(gca, 'YTick', ytrange)
set(gca, 'YTickLabel', ytlabel)
set(gca, 'FontSize',ticksize)
outname2 = strcat(tname,'_subbjs');
% skips
[histFreq, histXout] = hist(t.skips ,xtrange);
f3 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1,'BaseValue',0.1);
xlabel('# skips','FontSize',labsize);
ylabel('% students', 'FontSize',labsize);
xlim(xlimrange)
ylim(ylimrange)
set(gca, 'Yscale', 'log')
set(gca, 'YTick', ytrange)
set(gca, 'XTick', xtrange)
set(gca, 'YTickLabel', ytlabel)
set(gca, 'FontSize',ticksize)
outname3 = strcat(tname,'_skips');
% sub skips
[histFreq, histXout] = hist(t.bjs ,xtrange);
f4 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1,'BaseValue',0.1);
xlabel('# sub-skips','FontSize',labsize);
ylabel('% students', 'FontSize',labsize);
xlim(xlimrange)
ylim(ylimrange)
set(gca, 'Yscale', 'log')
set(gca, 'XTick', xtrange)
set(gca, 'YTick', ytrange)
set(gca, 'YTickLabel', ytlabel)
set(gca, 'FontSize',ticksize)
outname4 = strcat(tname,'_subskips');
% finally export all of the images
result = input('Press enter to export images. ','s');
saveas(f1, outname1, 'fig')
saveas(f1, outname1, 'png')
saveas(f2, outname2, 'fig')
saveas(f2, outname2, 'png')
saveas(f3, outname3, 'fig')
saveas(f3, outname3, 'png')
saveas(f4, outname4, 'fig')
saveas(f4, outname4, 'png')
function [] = genDurPlots( t )
% starting up
close all
now = 'starting script...'
% get table info
[r c] = size(t);
tname = inputname(1)
t.diff = t.max - t.min;
% sorting registered and anon
anonCell = strfind(t.sid,'anon');
anonLog = ~cellfun(@isempty,anonCell);
anon = t(anonLog,:);
regCell = strfind(t.sid,'reg');
regLog = ~cellfun(@isempty,regCell);
reg = t(regLog,:);
% insert code to rewrite csv with day diff
writetable(t,strcat(tname,'.all.csv'))
writetable(anon,strcat(tname,'.anon.csv'))
writetable(reg,strcat(tname,'.reg.csv'))
% generate stats for all
tmean = mean(t.diff)
tmedian = median(t.diff)
amean = mean(anon.diff)
amedian = median(anon.diff)
rmean = mean(reg.diff)
rmedian = median(reg.diff)
% generate histogram
[histFreq, histXout] = hist(t.diff,10);
f1 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1);
xlim([0,200])
title(tname,'FontSize',50)
xlabel('days','FontSize',40)
ylabel('% students','FontSize',40)
set(gca,'FontSize',25)
% generate histogram
[histFreq, histXout] = hist(anon.diff,10);
f2 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1);
xlim([0,200])
title('unregistered','FontSize',50)
xlabel('days','FontSize',40)
ylabel('% students','FontSize',40)
set(gca,'FontSize',25)
% generate histogram
[histFreq, histXout] = hist(reg.diff,10);
f3 = figure;
bar(histXout, histFreq/sum(histFreq)*100,1);
xlim([0,200])
title('registered','FontSize',50)
xlabel('days','FontSize',40)
ylabel('% students','FontSize',40)
set(gca,'FontSize',25)
outname = strcat(tname,'_timediff');
saveas(f1, outname, 'fig');
saveas(f1, outname, 'png');
outname1 = strcat(outname,'_anon');
saveas(f2, outname1, 'fig');
saveas(f2, outname1, 'png');
outname2 = strcat(outname,'_reg');
saveas(f3, outname2, 'fig');
saveas(f3, outname2, 'png');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment