MATLAB: Do I receive the M-Lint warning “The value assigned to variable might be unused” when the variable name is used as an argument to SAVE

MATLAB

I have the following function:
function myFunction
saveme = test;
save('test.mat', 'saveme')
I receive an M-Lint warning that variable 'saveme' is unused, even though I have passed it to the SAVE function.

Best Answer

The reason for the warning message is that the variable name 'saveme' is being passed as a string input parameter to SAVE. MATLAB does not recognize that this string corresponds to the variable 'saveme' until it evaluates the SAVE function at runtime.
If you would like to prevent this M-Lint message from being displayed, type
%#ok

at the end of the line that line that produces the warning. For example:
function myFunction
saveme = test; %#ok
save('test.mat', 'saveme')
Alternatively, you may use the command format syntax for SAVE:
save test.mat saveme
instead of the function syntax.