Filter löschen
Filter löschen

How to add NaN columns in a vector?

7 Ansichten (letzte 30 Tage)
Syed Wafa
Syed Wafa am 26 Feb. 2017
Bearbeitet: Roger Stafford am 26 Feb. 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.

Antworten (1)

Roger Stafford
Roger Stafford am 26 Feb. 2017
Bearbeitet: Roger Stafford am 26 Feb. 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.)

Kategorien

Mehr zu Code Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by