I have a vector with NaNs:
v1 = [NaN NaN NaN NaN NaN];
another vector with different values:
v2 = [1 4 6 8 9];
and linear index:
idx = [1 0 4 0 3];
I would like to assign values in v2 to v1 according to linear index so the result would be:
v1 = [1 NaN 8 NaN 6];
v1(idx ~= 0) = v2(idx(idx ~= 0))
This takes
"The values in v1
where idx
is not equal to zero"
and assigns them the values in
" v2
, at indexes idx
, where idx
is also not equal to zero"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.