MATLAB: How to generate and calculate with empty values of matrix-elements

logical?MATLABmatrix manipulation

PROBLEM:
I want to use logical functions to perform calculations between
matrices and don't know how to generate an empty value NaN.
EXAMPLE:
I use the two matrices below and if the conditions are not satisfied,
the output should be empty:
clear all;
close all;
m=rand(10,5);
n=rand(10,5);
T = zeros(size(m)); % Make another array to fill up…
for i = 1:numel(m)
if m(i)>.5 && n(i)>.5
T(i) = m(i+1)+n(i+1);
else
T(i) = 'NaN';
end
end
However, I obtain the following error:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
I hope someone know the correction of this mistake
Thank you in advance
Emerson

Best Answer

T(i) = 'NaN';
is wrong, your arrays have numeric values but you are trying to put one string in the array, you can't mix numeric values with strings on arrays, do this instead:
T(i) = NaN;
See this simple example:
a=[1 2;3 4];a(1)='NaN'; %error because of what I told you
a=[1 2;3 4];a(1)=NaN; %No error