如何用统一替换所有非NAN值?
问题描述:
我有一个3500 * 7500矩阵,其中有NAN和其他值.我想基本上将所有非NAN值都转换为1.
I have a 3500*7500 matrix where I have NAN and other values. I want to basically convert all non-NAN values with 1.
我可以使用〜isnan(mat)将NAN转换为0,将非NAN转换为1.
I can use ~isnan(mat) to convert NAN to 0 and non-NAN to 1.
是否存在类似的功能,可以将非NAN值转换为1,并保持NAN不变.
Is there a similar function to convert non-NAN values with 1 and leaving NANs as they are.
答
尝试:
mat(~isnan(mat)) = 1
这会将所有非NaN值设置为1
this will set to 1 all non NaN values