|
"Gabriel Peyr?" <gabriel.removethis.peyre@ceremade.removethat.dauphine.fr>
wrote in message news:g83hpt$95b$1@fred.mathworks.com...
>> Why not just remove the code you want to be missing,
>> save it as a different file name, and then publish that?
>
> Some of the removed part might be critical (the remaining
> part of the code will not be valid anymore).
Keep in mind that script files execute in the workspace of their caller, so
if you're worried that the code that you're removing depends on variables in
that workspace, you can put the removed code in a script. As an example,
try saving these two files and publishing file1.m:
--- Begin file1.m ---
%% Setup
% This is an example
a = 1;
b = 2;
%% Your assignment
% Your assignment, should you choose to accept it,
% is to recreate the figure below using an M-file.
% Assume that a and b are defined as above.
exerciseSolution;
--- End file1.m ---
--- Begin exerciseSolution.m ---
x = -10:0.1:10;
y = a*x+b;
plot(x, y)
--- End exerciseSolution.m ---
One benefit from this is, if you're using this to create homework for a
course (which I believe was the use case you mentioned in your original
message) you can simply distribute exerciseSolution after the assignment has
been submitted to demonstrate the answer.
If the piece of code you want to remove is _part_ of an expression, well
there's no way that I know of to pull just part of an expression into a
script or to hide it from being published. In that case, I think if you
want to hide the part you'll need to break off the whole expression into a
separate script or function file.
--
Steve Lord
slord@mathworks.com
|