MATLAB: Reduce each vector in a cell array

cell arraycircularfor loopmatrix manipulation

Hello, I have an image with a circular shape at center and I need to detrend each vector of the matrix avoiding the outside value, which is equal to 0. If I would like to have just the circular shape (so not a squared or rectangular matrix) how can I do? I created a loop to have a new matrix where 0 value is equal 0 and 1 all the other values (cause I need the index to reduce each vector). Now I was thinking to do that with a cell array an put inside the portion of each vector characterized by 1 value, but with the lines I wrote it gives me just the first vector. Any suggestion or new idea to solve the problem?
for jj = [1:n] %n is the number of the raw
kk=1:n/2; % n/2 number of columns
d1(jj,kk)=new1(jj,:) ~= 5958 ; % new1 is my matrix
data.b3=cell (1,n);
data.b3= find(d1(jj,kk) == 1 );
end

Best Answer

I do not understand what you want to achieve. So just some comments to your code and a bold guess:
d1 = zeros(n, n/2);
data.b3 = cell(1, jj);
for jj = 1:n % Without square brackets
% Not needed: kk=1:n/2; % n/2 number of columns
d1(jj, :) = (new1(jj,:) ~= 5958);
% Not needed: data.b3=cell (1,n);
data.b3{jj} = find(d1(jj, :) == 1);
end
Perhaps this is easier:
result = (new1 ~= 5958);
And then use the rows with "logical indexing" (search for this term in the net).
But perhaps you meant something completely different.