MATLAB: Using sscanf and NaN

datalinenanreadsscanftext;

Greetings,
So if i have the following:
a = '21414839.260 112535757.19909 2294.184 21414838.320 87690207.10148 1787.672'
Using:
A=sscanf(a,'%f')
Will return:
A =
1.0e+08 *
0.2141
1.1254
0.0000
0.2141
0.8769
0.0000
But if If the last 3 numbers are missing from the line :
a = '21414839.260 112535757.19909 2294.184 '
I want this to be returned:
A =
1.0e+08 *
0.2141
1.1254
0.0000
NaN
NaN
NaN
How can I make this possible?

Best Answer

If you know that sscanf of the input string is to return 6 numbers, and A is only populated with three, then you could do the following
A = [A; repmat(NaN,6-length(A),1)];