MATLAB/Wikiquiz writer (MATLAB)/write25versions.m

function  [pagedone]= write25versions( quizarray,headertext,extralines, textline1,textline2)
%WRITEFIRSTPAGE writes the first page, consisting of two conceptual tests,
%the first in original question order but with answers random, the second
%with both random.
%firstpagedone=false; don't think I need
%start remove (comment out)
questioncount=size(quizarray,1);
%Output first page, with two wikiquizzes,
outputfilename = ['outputFolder/' headertext ' 25 versions.txt'];
fout = fopen(outputfilename, 'w+');
if extralines>0 
    s =textline1; 
    fprintf(fout,'%s\n',s); 
end;
%s ='* [[/Testbank/]]<ref>software by user:Clockworks</ref>';  fprintf(fout,'%s\n',s);
if extralines>1 
    s =textline2; 
    fprintf(fout,'%s\n',s); 
end;
for versioncount = 2:26
    x=char(versioncount+64);
s =['== ',headertext,' ','version ',' ',x,' =='];  fprintf(fout,'%s\n',s);
s ='<quiz display=simple>';  fprintf(fout,'%s\n',s);
 orderofquestions=randperm(questioncount);
for questionindex = 1:questioncount
    questionposition=orderofquestions(questionindex);%we are  randomizing questions
    answercount = cell2mat(quizarray(questionposition,2));
    orderofanswers=randperm(answercount);
    if answercount==2
        orderofanswers=[1 2];
    end
    s=char(quizarray(questionposition,1));
    fprintf(fout,'%s\n',s);% prints question
    for answerindex = 1:answercount
        answerposition=orderofanswers(answerindex);
        s=char(quizarray(questionposition,answerposition+2));
        sa=[char(96+answerindex) ') '];
        sb=[s(1),sa,s(2:end)];%If problems arise replace 3 by 2
     fprintf(fout,'%s\n',[sb]);%  prints answer
    end
    s=' ';
    fprintf(fout,'%s\n',s);
end
s ='</quiz>';  fprintf(fout,'%s\n',s);
end
fclose(fout);
pagedone=true;

end