I am doing a program for students. They can load their matlab code in the matlab program, and the program is supposed to execute the student's code and check if the output is correct, and if is not, the program must point out the wrong line code. So I think this is a kind of metaprogramming. Right now I am trying to use the eval() function in order to execute the input text as code, but I don't know if this is a good idea. Also I am having problems to maintain the variables in the workspace because when I change from one method to another, the workspace variables are reset, so I am thinking in solving this problem saving and loading the workspace in a file, but may be you can suggest other and better ideas.
For now, we have predefined exercises the student must solve, the output of the program is always one or several images, because this is for image processing class. Here one example of code:
X=double(LENNA_G);
Y=medfilt2(X,[7 7]);
ps=psnr(Y,X,255);
disp(sprintf('%f[dB]',ps));
subplot(1,3,1);
imagesc(X,[0 255]);
colormap(gray(256))
axis image
subplot(1,3,2);
imagesc(Y,[0 255]);
axis image
subplot(1,3,3);
imagesc(X-Y,[-10 10]);
axis image
After executing code, the resulting images are compared to correct images (predefined images), and must be the same. If they are not, then the program must point out at least the line of code in which the error could be. I don't know if I made my self understood =/.
Thank you in advance.
From the comments, I would propose this solution. Hand out a template to your students:
function solution=exercise1(image1,image2)
%A) extract the r, g and b channel from the imag1e
solution.a.r=nan;
solution.a.g=nan;
solution.a.b=nan;
%B) convert the image2 to greyscale
solution.b=nan;
end
Then you can call the function exercise1 and compare field by field, everything you need is a recursive comparison of structs which outputs the fieldnames with differences. You could also provide a script template instead of a function template, but then your students must create separate files for their functions. This way the functions can be created in the same file, keeping them private and avoiding namespace conflicts.