MATLAB/Wikiquiz writer (MATLAB)/quizToStringArray.m
< MATLAB < Wikiquiz writer (MATLAB)function quizarray= wikiquizToStringArray(quizname) %WIKIQUIZTOSTRINGARRAY converts a quiz to a string array. The latest %upgrade removes % % clear;clc; % fid = fopen(quizname, 'r'); tline=fgetl(fid); raw = {tline}; rawlinecount=0; while ischar(tline)%count lines in raw wikitest tline=fgetl(fid); rawlinecount=rawlinecount+1; end fclose(fid); fid = fopen(quizname);%reopen raw cell array raw=cell(rawlinecount,1); % Fill cell array raw and replace nolines by whitespaces % Also count the questions questioncount=0; rawlineindex=0; while rawlineindex<rawlinecount rawlineindex=rawlineindex+1; tline=fgetl(fid); if numel(tline)==0 %add whitespace tline=' '; end raw{rawlineindex}=tline; if tline(1)=='{' questioncount=questioncount+1; end end fclose(fid); % % quizarray=cell(questioncount,7); %creates empty cell array questionindex=0; for rawlineindex=1:rawlinecount tline=raw(rawlineindex); %readsline cleanline=char(tline); %convert to string array switch cleanline(1) case '{' questionindex=questionindex+1; answerindex=0; question = cleanline; quizarray{questionindex,1} = cleanline; case '+' answerindex=answerindex+1; quizarray{questionindex,2} = answerindex; quizarray{questionindex,2+answerindex} = cleanline; case '-' answerindex=answerindex+1; quizarray{questionindex,2} = answerindex; quizarray{questionindex,2+answerindex} = cleanline; case ' ' %do nothing case '<' %do nothing case '=' %do nothing otherwise question=[question ' ' cleanline]; quizarray{questionindex,1} = question; end end % %
This article is issued from Wikiversity - version of the Saturday, November 15, 2014. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.