This is explained in the documentation here:
There is a general example code, and a specific one which is close to what you want.
ChatGPT can help with the necessary adjustments I believe. Here is what it proposes when I ask it to read the docs and then feed it your question (I didn't run this, but looks good to me):
options.stopfun = @mystopfun;
[x, xcost, info, options] = mysolver(problem, [], options);
function [stopnow, reason] = mystopfun(problem, x, info, last)
stopnow = false;
reason = '';
if numel(info) >= 2
f_k = info(last-1).cost;
f_kp1 = info(last).cost;
if abs(f_kp1 - f_k) < 0.01 * abs(f_k)
stopnow = true;
reason = sprintf('|f_{k+1}–f_k| < 1%% |f_k| ( %.3g )', abs(f_kp1 - f_k));
end
end
end