MATLAB/Wikiquiz writer (MATLAB)/Numeric/main.m
< MATLAB < Wikiquiz writer (MATLAB) < Numericfunction [void]=main(void) %NO EDIT %MAIN is the program you run to create the wikiquizzes after %testeditor.m has been suitably modified. But you do not edit MAIN. % variable list (may be outdated) %NO EDIT % wikiMatrix(answer,wikiDR,wikiSigFig) %NO EDIT % wikiType = 1 most of the time.%NO EDIT % WikiSigFig is called sf in bookeeping.%NO EDIT clear all; close all; clc; %clear here because we begin here. [ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor( );%NO EDIT cellsofar{1,1}=wikiHeadABC;%%NO EDIT First line of a wikiquiz for index=65:67%NO EDIT [ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor( );%NO EDIT cellsofar=startonequiz(wikiName,char(index) , wikiFirst, cellsofar);% ... <quiz display=simple> cellsofar=finishthequiz(wikiMatrix,wikiCell,1, cellsofar);% ... </quiz> printafile([wikiName 'ABC'],cellsofar);%NO EDIT end%NO EDIT clear cellsofar;%NO EDIT cellsofar{1,1}=wikiHeadD_Z;%First line of a wikiquiz %NO EDIT for index=68:90%NO EDIT [ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor( );%NO EDIT cellsofar=startonequiz(wikiName,char(index) , wikiFirst, cellsofar);% ... <quiz display=simple> cellsofar=finishthequiz(wikiMatrix,wikiCell,1, cellsofar);% ... </quiz> printafile([wikiName 'D_Z'],cellsofar);%NO EDIT end%NO EDIT %NO EDIT %%% functions %%%%%NO EDIT function [cellsofar]=finishthequiz(wikiMatrix,wikiCell,wikiType, cellsofar)%NO EDIT % FINISHTHEQUIZ finishes a wikiquiz with </quiz> nQues=size(wikiMatrix,1);%NO EDIT for iQues=1:nQues%NO EDIT cellsofar{size(cellsofar,1)+1,1}=['{',char(wikiCell(iQues,1)),'}'];%NO EDIT anspos = randi([1,5]);%NO EDIT for iAns=1:5%NO EDIT lett=char(96+iAns);%NO EDIT if iAns==anspos%NO EDIT key = '+';%NO EDIT else%NO EDIT key = '-';%NO EDIT end%NO EDIT s=[key,lett,') '];%NO EDIT %%%%%%%%The default is wikiType =1%%%%%%%%%NO EDIT %This default multiplies the answer by 10^(n/N) where N=wikiDR=wikiMatrix(:,2) if wikiType ==1%NO EDIT ef=10^((iAns-anspos)/wikiMatrix(iQues,2));%NO EDIT sf=num2str(wikiMatrix(iQues,3)); % = wikiSigFig in testeditor form=['%.' sf 'E'];%NO EDIT num = num2str(ef*wikiMatrix(iQues,1),form);%NO EDIT end%NO EDIT %%%%%%%%%%%%%% wikiType not yet incorporated%%%%%%%% if wikiType==2%NO EDIT ef=iAns-anspos; %ef is now what is added or subtracted sf=num2str(WikiMatrix(iQues,3));%NO EDIT form=['%6.' sf 'f']; % now floating point num = num2str(ef+WikiMatrix(iQues,1),form);%NO EDIT end %NO EDIT %end copy to below %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% s=[s num ' ' char(wikiCell(iQues,2))];%NO EDIT cellsofar{size(cellsofar,1)+1,1}=s;%NO EDIT end%NO EDIT cellsofar{size(cellsofar,1)+1,1}= ' ' ;%NO EDIT end%NO EDIT cellsofar{size(cellsofar,1)+1,1}= '</quiz> ' ;%NO EDIT end%NO EDIT end%NO EDIT %NO EDIT function [cellsofar]=startonequiz(wikiName, letter ,wikiFirst,cellsofar)%NO EDIT %STARTONEQUIZ adds: ==wikiName letter== wikifirst <quiz... % cellsofar is appended to original cellsofar string = ['==' wikiName ' ' letter '=='];%NO EDIT cellsofar{size(cellsofar,1)+1,1}=string;%NO EDIT if ~strcmp(wikiFirst,'noIntroLine');%NO EDIT cellsofar{size(cellsofar,1)+1,1}=wikiFirst;%NO EDIT end%NO EDIT cellsofar{size(cellsofar,1)+1,1}= '<quiz display=simple>';%NO EDIT end%NO EDIT function []=printafile(filename,cellsofar)%NO EDIT %PRINTAFILE makes a txt file with the name filename that contains the cell array cellsofar fout=fopen([filename '.txt'], 'w+');%NO EDIT for count=1:size(cellsofar,1)%NO EDIT string=char(cellsofar(count,1));%NO EDIT fprintf(fout,'%s\n',char(string));%NO EDIT end%NO EDIT fclose(fout);%NO EDIT end%NO EDIT
This article is issued from Wikiversity - version of the Sunday, November 16, 2014. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.