Something like reshape but accounting for missing values

2 次查看(过去 30 天)
I have a columnwise array of x- and y-coordinates with values at those x,y pairs. The full set of coordinates is predetermined and known, but in this array there isn't a value at every x,y pair. When there's no value, it's just skipped, so the original array cannot be rearranged using reshape. For example, the original array may look like this
x1 y3 v13
x2 y2 v22
x2 y3 v23
x3 y1 v31
x3 y2 v32
x3 y3 v33
and I want this
NaN NaN v31
NaN v22 v32
v13 v23 v33
I want to rearrange this original array to put the values in an array whose size is determined by the full set of coordinates with NaNs where there are missing values, and I want it to be fast. It'd be kind of like reshape, except, because there are missing (not empty) values, I don't want to cut up the column in a regular way to reshape. I think if there was a 2D interpolation option that allowed one to replace the "missing" elements with a constant, that would work, but I can't find that. I would replace them with NaNs in that case.

回答(1 个)

Image Analyst
Image Analyst 2020-1-20
Perhaps fillmissing()?
Or scatteredInterpolant()? (Dee attached demo.)
  1 个评论
Daniel
Daniel 2020-1-20
fillmissing needs an element there to replace essentially. I have missing elements, so I have to first have a way to say where to fill. scatteredInterpolant would work if you could "interpolate" by putting a constant value wherever interpolation was required. In my case, I would put NaNs there.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by