Home > Uncategorized > moodle_numerical_quiz_examples.m

moodle_numerical_quiz_examples.m

% This script shows two examples of how to create numerical questions for the moodle
% learning environment.
%
% The script makes use of a function called create_moodle_numerical_quiz_questions (download from https://dadorran.wordpress.com) to parse a structured variable.
% These examples essentially show you how to to create the data structures
% required by the function.
%
% The first example is the most important one to understand. The other
% example really just demonstrate how to create more
% complicated problems.
%
%Created by David Dorran (david.dorran@gmail.com) Jan 2013

% Eg 1 ------------------------------------------------------------------------
% Basic Addition Example with two questions
data1.category_name = 'Basic Addition';

data1.question(1).question_name = 'Basic Addition';
data1.question(1).question_text = 'What is 2 + 3';
data1.question(1).question_answer = 5;
data1.question(1).question_tolerance = 0;

data1.question(2).question_name = 'Basic Addition'; %call this Basic Addition 2 if you like but it might be useful to use the same name to reduce possibility of answers being posted on the web
data1.question(2).question_text = 'What is 9.2 + 3.333';
data1.question(2).question_answer = 12.533;
data1.question(2).question_tolerance = 0.05;

create_moodle_numerical_quiz_questions(data1,'addition_example.xml')

% Eg 2------------------------------------------------------------------------
% Determine the maximum sample in a segment of a signal

% data is on the web - next four lines download the data and import into
% matlab (more recent versions of matlab ( > 7.1 ) allow you to do this on one line)
url = 'http://eleceng.dit.ie/dorran/quiz_data/examples/'; % change this to a location that you have access to
data_url = [url 'signal.zip'];
help_url = [url 'help.html'];

urlwrite(data_url,'url_data_temp.mat');
load('url_data_temp.mat');
delete('url_data_temp.mat');

% create the data structure
data2.category_name = 'Signal Maximum';

data2.question(1).question_name = 'Signal Maximum Question';
data2.question(1).question_text = ['Download and import the signal in the zip file located at   ' data_url '. <p>Determine the value of maximum sample in the signal from the ' num2str(seg_start) 'th to the ' num2str(seg_end) 'th sample, inclusive. <br> Note that that matlab''s indexing system is ''incorrect'' in that the 0th sample is indexed as the the 1st element in the data sequence i.e. signal(1) in matlab is the 0th sample of the discrete signal. <p>See ' help_url ' for a demonstration.'];
data2.question(1).question_answer = sum(signal(999:1999).^2);
data2.question(1).question_tolerance = (sum(signal(999:1999).^2))*.02; % 2 percent tolerance

% create another 100 questions like this automatically
min_seg_len = 100;
max_seg_len = 1000;
max_start = length(signal) - max_seg_len -1;
for k = 1: 100
    seg_len = round(min_seg_len + (max_seg_len - min_seg_len)*rand);
    seg_start = round(max_start*rand);
    seg_end = seg_start + seg_len; 
    data2.question(k+1).question_name = 'Signal Maximum Question';
    data2.question(k+1).question_text = ['Download and import the signal in the zip file located at   ' data_url '. <p>Determine the value of maximum sample in the signal from the ' num2str(seg_start) 'th to the ' num2str(seg_end) 'th sample, inclusive. <br> Note that that matlab''s indexing system is ''incorrect'' in that the 0th sample is indexed as the the 1st element in the data sequence i.e. signal(1) in matlab is the 0th sample of the discrete signal. <p>See ' help_url ' for a demonstration.'];
    data2.question(k+1).question_answer = sum(signal(seg_start-1:seg_end-1).^2);
    data2.question(k+1).question_tolerance = (sum(signal(seg_start-1:seg_end-1).^2))*.02; %2 percent tolerance
end


create_moodle_numerical_quiz_questions(data2,'signal_maximum_example.xml')
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: