MATLAB: What does for j = [1:i-1, i+1:n] mean

gauss jordan

function [ u ] = ident(a,b,n)
a(:,n+1) = b;
for i = 1:n
for j = [1:i-1, i+1:n]
a(i,:) = a(i,:)/a(i,i);
a(j,i:end) = a(j,i:end) - a(i,i:end)*a(j,i);
end
end
u = a;
end

Best Answer

for j = [1:i-1, i+1:n]
...
end
is the same as:
for j = 1:n
if j ~= i
...
end
end
It runs a loop over all numbers from 1 to n, but excludes i . The loop index is the concatenation of the vectors 1:i-1 and i+1:n .
You can simply try it:
n = 10;
i = 7;
for j = [1:i-1, i+1:n]
disp(j)
end
Related Question