I have a matrix A
and B
as the following:
A = [1 NaN 3 4 5 NaN NaN 8 9 10];
B = [2 6 7];
Matrix B
has the same size as there are NaN
values in matrix A
(so 3x1 in this case).
I would like to replace the NaN
values in the same order as the values appear in B
. So the output should look like:
A = [1 2 3 4 5 6 7 8 9 10];
I can replace the NaN
, if both matrices have the same size. For T = 10
and N = 1
, I would use:
for t=1:T
for i=1:N
if A == NaN
C(t,i) = B;
else
C(t,i) = A(t,i);
end
end
end
However, I would like to know whether I could compare these matrices and replace the values even if the matrices are of different size? Saying differently, if A = NaN
take the first value of B
. For the next A = NaN
take the second value in B
.
Aucun commentaire:
Enregistrer un commentaire