Yes, it is possible. You can go through the code given below to get an idea, but again modify it according to your application:
Input matrix:
A = [ 1 2 3 NaN NaN NaN NaN NaN 4 NaN NaN NaN NaN 6 7 8 9 10 NaN NaN
NaN NaN 1 2 3 4 NaN NaN NaN NaN 5 NaN NaN NaN 6 7 8 9 10 NaN
1 NaN NaN NaN 2 3 4 5 NaN 5 6 NaN NaN 7 8 9 10 11 3 4];
Converting the matrices into 1-D vector, so as to traverse it easily:
[r,c] = size(A);
n = r * c;
reshape(A,[1,n]);
A= A';
Assigning left(L) and right(R) handles:
Specify limit you want between two NaN's:
Main body of function:
while R <= n
if isnan( A( R ) )
L = R;
R = R + 1;
end
if R- L + 1 == Lim
Tem = zeros(1, Lim);
i = 1;
while i <= Lim
Tem(i) = A(L);
L = L + 1;
i = i + 1;
end
while R<=n && ~isnan( A( R ) )
R = R + 1;
end
L = R;
R = R + 1;
disp(Tem)
elseif isnan( A( L ) ) || isnan( A( R ) )
L = R;
R = R + 1;
else
R = R + 1;
end
end
0 Comments
Sign in to comment.