suppose age is the following vector [ 18 25 -1 22 32 -1 ]. give the matlab command(s) that change all the -1 values in age to nan. in matlab

You can replace all instances of -1 with NaN using the following MATLAB command:

main.m
age(age==-1) = NaN;
20 chars
2 lines

This command first creates a logical array with the same size as age by checking which elements are equal to -1, using the logical operator ==. It then uses this logical array to index into age, and sets the corresponding elements to NaN.

related categories

gistlibby LogSnag