Code will break in the case that all detected digits are the same, or all the same followed by pause. To fix that, replace "ct = 1" and the following "for" loop with code such as

y = r;
for i = length(r) : -1 : 2
if y(i) == y(i-1); y(i) = []; end
end
if y(end) == '-'; y(end) = []; end
if y(1) == '-'; y(1) = []; end

This might not be the most efficient version but sometimes it is not worth writing and debugging for maximum efficiency when more clarity will do the job.

I am trying "nldif" function, and find that there are two options for diffusion: one is "AOS" by aosiso.m and the other is "iso" by isodifstep.
For "AOS", the result is good when I choose stepSize = 2; But for "iso", I cannot get good result for any stepSize (from 0.01 to 1...).
I want to know what value of stepSize for "iso" case can get the same result as "aos". I suppose "aos" and "iso" should get the same result when choose proper stepSize. The only different should be the speed. Is it correct?
And when I try to feed back from "aos" result to "iso" stepSize ( (aosiso(y, g, 2) - y)/dy ), but I can not get a uniform stepSize value.

Can you help me to explain above case?

code for feedback:
========
% Calculate dy/dt
%if aos
% if plotflux
% yo = y;
% end
% y = aosiso(y,g,stepsize(i)); % updating
%else
% dy = isodifstep(y, g);
% y = y + stepsize(i) * dy; % updating
%end
tmp = y;
tmp1 = aosiso(y, g, 2) - tmp;
dy = isodifstep(y, g);
ios_step = tmp1 / dy;
=======

It looks like those who think this is an efficient tool (Hongjun, etc.) and therefore give it a good rating, don't understand how to use sparse matrices in MATLAB. In fact, a couple of those people talk about using inv. SIGH.

In fact, this tool REALLY is considerably slower than backslash, as long as you understand what you are doing. If you have no idea what you are doing, then quite likely you are using the wrong tools in MATLAB in any event.

n = 1000000;

B = rand(n,3);
B(:,2) = B(:,2) + 1;
A = spdiags(B,-1:1,n,n);

d = rand(n,1);

a = B(:,2);
b = B(2:n,3);
c = B(1:n-1,1);

tic
xt = thomas(a,b,c,d);
toc
Elapsed time is 1.727341 seconds.

tic
xs = A\d;
toc
Elapsed time is 0.125294 seconds.

See that thomas was roughly 14 times slower than backslash on the same problem. This is a major difference. backslash was more efficient for ANY size matrix, ranging from 5 to 20 times as fast in my tests on different size matrices.

Someone will be sure to think that I've not included the time to generate the sparse matrix itself, but the call to spdiags itself took only about 0.5 seconds. So even if I combine the two calls, it still is twice as fast to use backslash. If you will do other things with the sparse matrix A, then the call to spdiags is arguably spread across all the work you do, so it is more efficient yet.

The point is, there really is no need for thomas to exist at all, as far batter tools are available in MATLAB. Use backslash. And for gods sake, do NOT use inv.