How to add NaN columns in a vector?

10 visualizaciones (últimos 30 días)
Syed Wafa
Syed Wafa el 26 de Feb. de 2017
Editada: Roger Stafford el 26 de Feb. de 2017
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.

Respuestas (1)

Roger Stafford
Roger Stafford el 26 de Feb. de 2017
Editada: Roger Stafford el 26 de Feb. de 2017
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.)

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by