Try this:
RTc = [1 2 3 NaN; 4 5 6 7; NaN 8 9 10] % Create Matrix AccuracyC = randi(9, size(RTc)) % Create Matrix
AccuracyC(isnan(RTc)) = NaN % Desired Result
RTc =
1 2 3 NaN 4 5 6 7 NaN 8 9 10
AccuracyC =
7 1 6 6 8 3 9 3 1 8 2 1
AccuracyC =
7 1 6 NaN 8 3 9 3 NaN 8 2 1