How to add NaN columns in a vector?

11 次查看(过去 30 天)
I have a vector X which is a 1*38 double (x1,x2,x3,x4,x5,....x38). I want to calculate the difference between every adjacent cell (for example, between x3 and x4, x4 and x5 etc.) and if the difference is greater than 0.0002, I want NaN columns to be added between the two adjacent cells, such that the number of columns between adjacent cells will equal the difference divided by 0.0002.

回答(1 个)

Roger Stafford
Roger Stafford 2017-2-26
编辑:Roger Stafford 2017-2-26
Let X be your row vector.
p = cumsum([1,1+floor(abs(diff(X))/0.0002)]);
T = NaN(1,p(end));
T(p) = X;
X = T;
(Note: This doesn't reshape X. It extends its length by the insertion of NaNs.)

类别

Help CenterFile Exchange 中查找有关 Code Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by